Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Outer join issue?

Author  Topic 

marcelo73
Starting Member

14 Posts

Posted - 2006-11-22 : 16:28:14
I have 2 tables A and B.
I need to know what records doesn't exist at B whether in A they exist.

Table A
-------
F1 F2
1 desc1
2 desc2
3 desc3
4 desc4

Table B
-------
F1 F2
1 desc1
2 desc2
4 desc4


As a result I should get:

F1 F2
3 desc3


Thanks, Marcelo.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-11-22 : 16:41:23
[code]
select a.f1
,a.f2
from a
left outer join b
on b.F1 = a.F1
where b.f1 is null
[/code]

Be One with the Optimizer
TG
Go to Top of Page

vgr.raju
Yak Posting Veteran

95 Posts

Posted - 2006-11-22 : 16:58:05
If you are using sql server 2005,take a look at EXCEPT and INTERSECT Operators.

Returns distinct values by comparing the results of two queries.

EXCEPT returns any distinct values from the left query that are not also found on the right query.

INTERSECT returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand.

The basic rules for combining the result sets of two queries that use EXCEPT or INTERSECT are the following:

The number and the order of the columns must be the same in all queries.


The data types must be compatible.

Thanks!
Raju
http://www.trickylife-trickylife.blogspot.com/
Go to Top of Page
   

- Advertisement -