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 |
|
chessmonster
Starting Member
6 Posts |
Posted - 2011-06-02 : 12:43:59
|
| hi, sorry for the unclear title.I just would like to have some ideas on how I can retrieve rows that are not existing on another table. (it sounds unclear) well it like I have two tablestable1col1, col21, a 2, b3, c4, d5, eand table2col1, col22, b4, di have two tables here, what I would like to do if possible is to get the rows in table1 that are not existent in table2.result ids should be 1,3,5 coming from table.tried to do the <> operator but it seems like a failure. maybe some ideas folks? :D any would be appreciatedtoughness and stubborness |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-06-02 : 12:49:04
|
One possibility:select col1, col2from table1 t1where not exists( select * from table2 t2 where t1.col1 = t2.col1 and t1.col2 = t2.col2) Alternatively,select t1.col1, t2.col2from table1 t1 left join table2 t2 on t1.col1 = t2.col1 and t1.col2 = t2.col2where t2.col1 is not null |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-06-02 : 12:50:38
|
| select col1from table1exceptselect col1from table2select * from table1where col1 not in (select col1) from table2select t1.col1from table1 t1left join table2 t2 on t1.col1 = t2.col1where t2.col1 is nullJimEveryday I learn something that somebody else already knew |
 |
|
|
chessmonster
Starting Member
6 Posts |
Posted - 2011-06-02 : 13:10:50
|
| thanks for the both of the people who answered. both suggestion were helpful and importantly gave me some ideas.thanks ! solved it, used the not exists methodtoughness and stubborness |
 |
|
|
|
|
|
|
|