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)
 Not in table

Author  Topic 

jamesdwhite
Starting Member

9 Posts

Posted - 2007-02-27 : 13:46:14
i have a table table1, which contains fk userId which references table2 users. i want to select all the users from table users that aren't in table1 how can i do this

thanks

james

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2007-02-27 : 14:06:36
select userid from table2 except select userid from table1

but what is the key of table2?, I just assumed something...
____________________________________
got to love the new except operator!

rockmoose
Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2007-03-01 : 02:28:44
quote:
Originally posted by jamesdwhite

i have a table table1, which contains fk userId which references table2 users. i want to select all the users from table users that aren't in table1 how can i do this

thanks

james



try this ...

Select col1, col2 from table2 where col1 not in (select col1 from table1)

Mahesh
Go to Top of Page
   

- Advertisement -