Quality Testing

Quality is delighting customers

How to retrieve the records using a join where primary key and foreign key are different.

Hi all,

Here is a table details.

T1     T2

1        1

2        2

3        3

          A

          B

In the above table, I want to display only A and B using join. What join should i use?

Also how to retrieve top 100 rows in a join. I have tried giving  select top 100 ID from DB name inner join on DB name but it's throwing error.

I have gone through the joins concept many times but when it comes to querying, it always goes wrong. Can sme one help me sort out this.

Regards,

Jo

 

Views: 414

Reply to This

Replies to This Discussion

May i know, which database you r using...?

I'm using SQL server and this question was asked in an interview.

Difference between Primary Key & Foreign Key

Primary Key

 

Foreign Key

 

Primary key uniquely identify a record in the table.

 

Foreign key is a field in the table that is primary key in another table.

 

Primary Key can't accept null values.

 

Foreign key can accept multiple null value.

 

By default, Primary key is clustered index and data in the database table is physically organized in the sequence of clustered index.

We can have only one Primary key in a table.

 

Foreign key do not automatically create an index, clustered or non-clustered. You can manually create an index on foreign key.

We can have only one Primary key in a table.

 

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service