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 |
|
amarflora
Starting Member
4 Posts |
Posted - 2008-12-17 : 12:04:19
|
| Hello there,I have two tables with relationship with 'id' column in both tables. I a select command to fetch all the data from the 1st table but leave the ones which are already present in the second table.For exampleIn the first table, there are three rows with ID being 1,2 and 3.In the second table, there is one row with ID 1I want to output to be 2 and 3(Leaving 1 as it exists in second table)Thanks a lot for your help!! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 12:06:07
|
| [code]SELECT t1.*FROM table1 t1LEFT JOIN table2 t2on t1.id=t2.idwhere t2.id is null[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 12:06:57
|
| [code]SELECT t1.*FROM table1 t1WHERE NOT EXISTS (SELECT 1 FROM table2 WHERE id=t1.id)[/code] |
 |
|
|
amarflora
Starting Member
4 Posts |
Posted - 2008-12-17 : 14:08:20
|
| THANKS A LOT MATE. WORED FINE!!!:) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 23:20:33
|
welcome |
 |
|
|
|
|
|