Compare 2 tables 
Author Message
 Compare 2 tables

I need to select/delete data from table2 where the same
data (based only on 3 columns) is in table1.  Eg.

Table1

a,b,c,d,e,f,g
--------------
3,5,8,2,7,8,9
1,3,5,7,9,2,4
4,4,6,7,8,3,2
6,7,6,7,6,7,6,

Table2

a,b,c,d,e,f,g
--------------
3,5,8,2,7,8,9
2,2,2,3,4,5,6
5,6,5,5,4,3,2
6,7,6,1,2,1,1

So it would select/delete rows: 1 (3,5,8,2,7,8,9
) and 4 (6,7,6,1,2,1,1) in table2 cause they matched
columns a,b,c in table1.  Any suggestions?

I tried something like

select * from table2
where a,b,c in
select a,b,c from table1

but this doesn't work.

Any ideas?  Thanks.



Tue, 21 Mar 2006 19:58:21 GMT
 Compare 2 tables

DELETE FROM Table2
    WHERE EXISTS
        (SELECT *
            FROM Table1
            WHERE a = Table2.a
                AND b = Table2.b
                AND c = Table2.c)

--
David Portas
------------
Please reply only to the newsgroup
--



Tue, 21 Mar 2006 20:07:41 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. Comparing two tables and appending data to destination table

2. comparing two tables

3. Comparing 2 tables on 2 different servers

4. Comparing 2 tables

5. Compare two tables

6. Comparing Two Tables for Inaccuracies

7. Comparing two tables

8. compare 2 table schemas

9. Compare Two Tables

10. Comparing two tables in SQL 7.0 or SQL 6.5

11. NEWBIE: Comparing two tables using only a where-clause

12. comparing 2 tables


 
Powered by phpBB® Forum Software