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 2005 Forums
 Transact-SQL (2005)
 Basic query question...

Author  Topic 

Goalie35
Yak Posting Veteran

81 Posts

Posted - 2008-12-03 : 11:34:43
Ok, I should know this but right now the answer is slipping my mind...if I have 2 tables(tableA & tableB), how do I grab all values from tableA that are NOT located in tableB?

Ex:
TableA
--------
Orange
Apple
Banana
Grape

TableB
--------
Apple
Banana

So, in this example, I'll display the two values from tableA that aren't in tableB: "Orange" & "Grape".

Thanks.

-Goalie35

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-03 : 11:39:05
[code]SELECT field FROM TableA
EXCEPT
SELECT field FROM TableB
[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-03 : 11:40:55
Also

SELECT a.field
FROM TableA a
LEFT JOIN TableB b
ON b.field=a.field
WHERE b.field IS NULL



&

SELECT *
FROM TableA a
WHERE NOT EXISTS (SELECT 1
FROM TableB
WHERE field=a.field)
Go to Top of Page
   

- Advertisement -