D
D
DevalDi2020-11-02 14:44:01
SQL
DevalDi, 2020-11-02 14:44:01

Comparison of two sql tables with different structure. Maybe?

Hello.
I have in 1 database two tables that are different in structure, but have only 1 identical column.
Let's call them table1 and table2

I need to compare these columns in table1 and table2.
If we have in table1 in the ID column for example 10 and do not have the same id in the same column in table2, then we delete the entire row from table2.

You need to write a comparison query for 98,000 rows. Can sql do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Vodakov, 2020-11-02
@DevalDi

DELETE
FROM Таблица2
WHERE NOT(Таблица2.ID IN (SELECT ID FROM Таблица1))

L
Lazy @BojackHorseman, 2020-11-02
SQL

DELETE FROM <table1_name> t1
WHERE NOT EXISTS(SELECT 'x' FROM <table2_name> t2 WHERE t2.id = t1.id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question