Comparison of two tables in MYSQL
compare, database, mysql
Solution
Try this:
SELECT table1.*
FROM table1
LEFT OUTER JOIN table2
ON table1.id = table2.id
WHERE table2.id IS NULL
`LEFT OUTER JOIN` link two table starting by table1, if table2 has no linked row all fields of table2 will be null. So, if you put in your `WHERE` condition table2.id is null, you get only rows in table1 not existing in table2
Problem
I have two tables. One table (table1) has 28500 rows and the another (table2) has 17450 rows. I would like to compare these tables and find rows that do not exist in table1. ``` SELECT * FROM table1 WHERE ID NOT IN (SELECT DISTINCT(ID) FROM table2) ``` Any suggestions?