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.
Author |
Topic |
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2014-02-01 : 08:12:13
|
Hi, I have two tables with similar two columns as shown belowtable1code | organisation256 | abc832 | xyz893 | tax921 | abc951 | abctable2code | organisation951 | abc832 | xyz256 | abc893 | tax921 | taxNow, I want to check whether all the codes in table1 existing in table2 and list them, and if both columns from table1 is matching with the both columns in table2. For e.g. 256|abc in table1 is matching with 256|abc in table2The output should be :921 | taxFor e.g. 256abc is there or not in table2, |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-02-01 : 09:28:40
|
what do you want ?rows in table1 that does not exists in table2 ?select *from table1 t1where not exists ( select * from table2 t2 where t2.code = t1.code and t2.organisation = t1.organisation KH[spoiler]Time is always against us[/spoiler] |
|
|
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2014-02-01 : 12:49:58
|
Thanks It works |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-02 : 01:45:56
|
quote: Originally posted by khtan what do you want ?rows in table1 that does not exists in table2 ?select *from table1 t1where not exists ( select * from table2 t2 where t2.code = t1.code and t2.organisation = t1.organisation KH[spoiler]Time is always against us[/spoiler]
shouldnt it be the other way around seeing the sample output?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2014-02-02 : 07:28:47
|
HI Visakh, you are correct. But after I went through Khtan's code, I got an idea how this code works so I can use it as I want. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-02 : 11:57:23
|
quote: Originally posted by learning_grsql HI Visakh, you are correct. But after I went through Khtan's code, I got an idea how this code works so I can use it as I want.
Ok good just checked as I couldnt correlate your sample output with suggestion------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|