Author |
Topic |
sagavb
Starting Member
18 Posts |
Posted - 2009-06-12 : 06:04:54
|
Hi Friends,Here, i have 2 tables. I just want to find out the records from TableA which are not matched with TableBTableA:ID--A1A2A3TableB:ID--A1B1o/pID--A2A3primary key is IDCan anybody help on this?Thanks in advanceSaga |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-12 : 06:10:06
|
1. Use NOT EXISTS2. Use NOT IN3. Use LEFT JOIN E 12°55'05.63"N 56°04'39.26" |
|
|
sagavb
Starting Member
18 Posts |
Posted - 2009-06-12 : 06:12:51
|
hi Can you post me a query for the above exampleRegardsSagaquote: Originally posted by Peso 1. Use NOT EXISTS2. Use NOT IN3. Use LEFT JOIN E 12°55'05.63"N 56°04'39.26"
|
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-12 : 06:22:09
|
4. UNION ALLSELECT IDFROM ( SELECT 0 AS s, ID FROM TableA UNION ALL SELECT 1 AS s, ID FROM TableB ) AS dGROUP BY IDHAVING MAX(s) = 0 E 12°55'05.63"N 56°04'39.26" |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-06-12 : 08:08:37
|
quote: Originally posted by Peso 4. UNION ALLSELECT IDFROM ( SELECT 0 AS s, ID FROM TableA UNION ALL SELECT 1 AS s, ID FROM TableB ) AS dGROUP BY IDHAVING MAX(s) = 0 E 12°55'05.63"N 56°04'39.26"
Just horrible. but cool. Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-06-12 : 08:11:30
|
quote: Originally posted by sagavb hi Can you post me a query for the above exampleRegardsSagaquote: Originally posted by Peso 1. Use NOT EXISTS2. Use NOT IN3. Use LEFT JOIN E 12°55'05.63"N 56°04'39.26"
I generally use LEFT JOIN -- performance wise I understand that NOT EXISTS my be quicker but I find LEFT JOIN much easier to read.SELECT a.*FROM tableA a LEFT JOIN tableB b ON b.[Id] = a.[Id]WHERE b.[Id] IS NULL Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-12 : 08:28:44
|
quote: Originally posted by sagavb Hi Friends,Here, i have 2 tables. I just want to find out the records from TableA which are not matched with TableBTableA:ID--A1A2A3TableB:ID--A1B1o/pID--A2A3primary key is IDCan anybody help on this?Thanks in advanceSaga
Hi saga!Why so urgent???Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-12 : 08:29:39
|
quote: Originally posted by senthil_nagore
quote: Originally posted by sagavb Hi Friends,Here, i have 2 tables. I just want to find out the records from TableA which are not matched with TableBTableA:ID--A1A2A3TableB:ID--A1B1o/pID--A2A3primary key is IDCan anybody help on this?Thanks in advanceSaga
Hi saga!Why so urgent???select * from tab1 where id not in(select id from tab2)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled
Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-12 : 08:52:02
|
quote: Originally posted by Transact Charlie[brJust horrible. but cool.
Try out the performance on a million record table E 12°55'05.63"N 56°04'39.26" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|