Categories: MySQL

Compare two tables in MySQL

Share

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.

Recent Posts

Recover From Google Penalties in 10 Steps in 2024

Facing Google penalties can be a daunting challenge for businesses relying on organic search traffic.…

1 day ago

What is the Future of Artificial Intelligence?

Technology, undeniably, has made our lives easier. But the advent of artificial intelligence has been…

1 day ago

Role of guest post services in SEO

Guest post services have become an essential tool for businesses and individuals looking to increase…

2 days ago

Top Programming Trends You Need to Know in 2024

Programming continues to evolve at a rapid pace, with new trends and technologies emerging every…

2 days ago

Why startups need a digital marketing strategy?

Let’s be honest; a startup business hardly has sufficient amount to promote their services and…

3 days ago

How to Find the Best SEO Consultant in Toronto to Boost Your Rankings

Introduction In today's digital age, having a strong online presence is crucial for businesses in…

3 days ago