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 |
|
jfm
Posting Yak Master
145 Posts |
Posted - 2012-07-16 : 05:23:03
|
| Hi there, I have two different tables (Table_Jan, Table_feb) with the same columns.I need to take from column_1 of Table_feb all the values that don't appear in column_1 table_jan. That way, I can know, which values of column_1 have disappeared in Table_feb.Any idea? Thanks |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-16 : 05:33:30
|
| SELECT * FROM TabFebWHERE Col1 NOT IN (SELECT Col1 FROM TabJan)--------------------------http://connectsql.blogspot.com/ |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-16 : 05:36:42
|
| OR you can use it with joinsSELECT tf.* FROM TabFeb tfLEFT OUTER JOIN TabJan tjON tf.COL1 = tj.COL1WHERE TJ.COL1 IS NULL--------------------------http://connectsql.blogspot.com/ |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-16 : 05:38:11
|
| Or you can use EXCEPTSELECT * FROM TabFebEXCEPTSELECT * FROM TabJan--------------------------http://connectsql.blogspot.com/ |
 |
|
|
jfm
Posting Yak Master
145 Posts |
Posted - 2012-07-16 : 06:00:52
|
| Thanks so much, Im trying to use: SELECT company, plate, SUM (workers) FROM table_febWHERE id NOT IN (SELECT id FROM table_jan) AND colour='b' GROUP BY companyORDER BY companymsg 8120, level 16, state 1, line 1You know why? If I use other queries, is not recognizing the condition AND.. Many thanks |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-16 : 11:04:00
|
| SELECT company, plate, SUM(workers)FROM table_febWHERE id NOT IN ( SELECT id FROM table_jan ) AND colour = 'b'GROUP BY company, plate--------------------------http://connectsql.blogspot.com/ |
 |
|
|
|
|
|
|
|