Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining two tables

Status
Not open for further replies.

abhishekpant

Programmer
Dec 21, 2004
38
0
0
US
All

I have two table A and B.
I need to find out the records in table A which are not present in table B

The both the table have secutity ID.

So basically i need to find out that the list of securityId which are present in table A and not in table B.

Can someone help??

Thanks
Abhi

 
Code:
Select TableA.SecurityId
From   TableA
       Left Join TableB
         On TableA.SecurityId = TableB.SecurityId
Where  TableB.SecurityId Is NULL

When you left join a table, you get all the records from the 'table to the left of the join' and matching records from the table on the right. If there is no match, then the TableB values will be null.

Make sense?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks Goerge

But I need to find out the Ids which are present in table A but not In table B

Does this query do the same thing??

Thanks
Abhi
 
Try it. [wink]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
You still need to read my link so you understand why it works. This is basic stuf that you need to know backwards and forwards and be able to do without even thinking about it.

"NOTHING is more important in a database than integrity." ESquared
 
I agree with SQLSister. The Left Join is one of my favorite SQL Server statements. I encourage you to learn it well.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top