I want a query that will give me all rows that are in one table but not in
another.
For example:
Table1.ID Table2.ID Result.ID
1 1 4
2 2 5
3 3 6
4
5
6
Thanks
Try:
select id from table1 a
where not exists
(select * from table2 b
where a.id = b.id)
Vishal Parkar
vgparkar@.yahoo.co.in | vgparkar@.hotmail.com
|||That seems to work well. Now I'd like to add the result back into the second
table so that table2 ends up like table1.
I tried:
INSERT INTO table2 ( id )
SELECT table1.id FROM table1 WHERE NOT EXISTS
( SELECT table2.id FROM table2 WHERE table1.id = table2.id )
but that doesn't seem to work.
"Vishal Parkar" wrote:
> Try:
> select id from table1 a
> where not exists
> (select * from table2 b
> where a.id = b.id)
> --
> Vishal Parkar
> vgparkar@.yahoo.co.in | vgparkar@.hotmail.com
>
>
|||i dont know why it shouldn't work. are you getting any error?
see following example.
create table table1(id int)
create table table2(id int)
insert into table1 values(1)
insert into table1 values(2)
insert into table1 values(3)
insert into table2 values(1)
insert into table2 values(2)
INSERT INTO table2 ( id )
SELECT table1.id FROM table1 WHERE NOT EXISTS
( SELECT table2.id FROM table2 WHERE table1.id = table2.id )
Vishal Parkar
vgparkar@.yahoo.co.in | vgparkar@.hotmail.com
No comments:
Post a Comment