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
 General SQL Server Forums
 New to SQL Server Programming
 Getting records from one table not in another

Author  Topic 

cemiess
Starting Member

1 Post

Posted - 2009-11-27 : 09:49:07
I've read a few ways of doing this, LEFT JOINs, UNIONs, NOT EXISTS and NOT INs, but none of them quite do what I need.

The problem is that in the tables I'm using, there is a "uid" that can exist multiple times, and that is what I'm comparing the tables on. There is a "mid" field that is unique, but it's only in the 1st table.

Also in the first table is a "list_" column, which provides normalisation of sorts, no 2 uids can have the same list_.

Needless to say this is not a database I made...

I'm quite new to sql, and this is providing a bit of a challenge for me, so any help would be greatly appreciated.

I need to do 2 queries, ie

All the records in table a but not in table b
and
All the records in table b but not in table a

Thanks in advance.



http://resourcebasedliving.com

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-27 : 22:19:19
seems like this

SELECT fields....
FROM TableA a
WHERE NOT EXISTS (SELECT 1 FROM TableB WHERE uid =a.uid)
UNION ALL
SELECT fields....
FROM TableB b
WHERE NOT EXISTS (SELECT 1 FROM TableA WHERE uid =b.uid)
Go to Top of Page
   

- Advertisement -