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 stmt

Author  Topic 

hibah
Starting Member

1 Post

Posted - 2008-11-24 : 08:03:48
Hello,

How can i write sql stmt were i want to get all the resord in table 1 an dnot in table 2 accoring to 2 feilds in the table f1 and f2. I tried to use "Not In " but it only takes one feild.
note the i want to check both feilds not each alone meaning both f and f2 together.


Thx

Hiba

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 08:38:50
[code]SELECT t1.*
FROM table1 t1
LEFT JOIN table2 t2
ON t2.f1=t1.f1
AND t2.f2=t1.f2
WHERE t2.f1 IS NULL [/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-24 : 08:54:03
Your closest equivalent is [NOT] EXISTS.
SELECT	t1.*
FROM table1 AS t1
WHERE NOT EXISTS (SELECT * FROM Table2 AS t2 WHERE t2.f1 = t1.f1 AND t2.f2 = t1.f2)



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -