| Author |
Topic |
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2011-10-28 : 04:36:55
|
| Table1Name:-----PaulRingoJohnPaulGeorgeRingoTable2Name------SteveGeorgePeterPaulJohnGeorgeI want all those records from Table1 who's names are not in the List of Table2; in this case the wanted result isRingoRingo how can I achieve this?Martin |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-10-28 : 04:39:10
|
select name from table1 as t1where not exists(select * from table2 as t2 where t1.name=t2.name) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-10-28 : 04:42:03
|
select name from table1 exceptselect name from table2 N 56°04'39.26"E 12°55'05.63" |
 |
|
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2011-10-28 : 04:42:51
|
| Now that was quick... thank you!!! |
 |
|
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2011-10-28 : 06:47:22
|
| @SwePeso: This query just returns one "Ringo" - I need all the records from Table1, that do not exist in Table2@Webfred: I can't adapt the syntax to my query as table1 is a inner join relationship... :( Could save it as a new table and refer to it that way, but I rather learn how to do this in one expression.table1:select * from table1 inner join table3 on table1.xx = table3.xxSo in application to your query I try:select * from table1 inner join table3 on table1.xx = table3.xx as t1where not exists(select * from table2 as t2 where t1.name=t2.name)Incorrect syntax near the keyword 'as'hmmm... Martin |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-28 : 06:56:20
|
you can use likeselect t1.*from(select * from table1 inner join table3 on table1.xx = table3.xx) as t1where not exists(select * from table2 as t2 where t1.name=t2.name) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2011-10-28 : 07:19:24
|
| Nice! Now it works!!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-28 : 07:22:52
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|