Answer the question
In order to leave comments, you need to log in
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
DELETE
FROM Таблица2
WHERE NOT(Таблица2.ID IN (SELECT ID FROM Таблица1))
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 questionAsk a Question
731 491 924 answers to any question