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)
 how to filter rows without any foreign key

Author  Topic 

asim.khan007
Starting Member

4 Posts

Posted - 2008-03-13 : 14:04:17
i have two tables with primary key and foreign key
how can i filter the data to only show rows which do not have any foreign key

like

table1 table2
Primary key foreign key

1 5
2 4
3 3
4
5


how can i show rows

1 and 2 in table1 ?

Thanks

X002548
Not Just a Number

15586 Posts

Posted - 2008-03-13 : 14:24:19
SELECT t1.* FROM TABLE1 t1 LEFT JOIN TABLE2 t2 ON t1.key = t2.key WHERE t2 IS NULL

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

asim.khan007
Starting Member

4 Posts

Posted - 2008-03-14 : 02:50:26
Thank you very much :)
Go to Top of Page
   

- Advertisement -