spaniard89 spaniard89 - 1 month ago 6
SQL Question

Comparing tables that do not have same number of rows but same number of columns

I have two tables for instance Table

A
and Table
B
.

Table
A
and
B
has same number of columns, but table
A
has few extra rows.

I was wondering if there's a query that would compare Table
A
and
B
and delete the extra number of rows that exist in Table
A
.

And also it would be good to have a temp table that would the values that were deleted. A

Any suggestions?

Answer

Try this: [Edited]

Delete from A where id in 
             (
                Select id from ((select id from A) minus (select id from B))
             );

Above query assumes that A and B have same columns which includes an id column [which is unique].

Comments