Compare two tables in MySQL

MySQL CASE

When migrate data you need to compare two tables and identify the unmatched results records.

Suppose you have two tables table1 and table2 with same columns and values. If any one table has any extra row then using below query you can get the unmatched results.

Compare two tables:

SELECT id, name
FROM (
SELECT id, name FROM table1
UNION ALL
SELECT id, name FROM table2
) tbl
GROUP BY id, name
HAVING count(*) = 1
ORDER BY id;

Using above query you will get the unmatched row.

For any types of queries, you can contact us on info@namasteui.com.

You may like:  Database Manage in MySQL

Leave a Reply

Your email address will not be published. Required fields are marked *