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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Left Join question

Status
Not open for further replies.

KiwiGuy

Technical User
Mar 13, 2001
15
0
0
GB
Hey All,

Ive got 2 tables im trying get some results from

Table1 Table2
Fields A B A B
1 2 1 2
3 4 3 4
5 6

being a ms sql server man to get the items not matching between table 1 and 2, that are on table1 i would do the following

Select * from Table1,Table2 where Table1.A*=Table2.B and Table1.B*=Table2.B and (Table2.A is NULL)

the is null statement shoule give me all items in Table1 where there is no match with Table2, this doesnt work in SYBASE, How would i do this, HELP!!!!!

Cheers
 
Hiya,

I may have misunderstood the question, but I think that you only want what is in table 1 and not in table 2 returned. In this case, you should be able to use NOT EXISTS

SELECT t1.*
FROM table1
WHERE NOT EXISTS (SELECT 1
FROM table2 t2
WHERE t1.a = t2.a
AND t1.b = t2.b)

That should just give you 5 and 6 returned.

HTH

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top