Hi ,
I have a doubt in Mysql.I want to compare two tables and bring the unmatched records from both the tables.

Thank You,
Prem

SELECT MIN (tbl_name) AS tbl_name, PK, column_list
FROM
(
SELECT ' source_table ' as tbl_name, S.PK, S.column_list
FROM source_table AS S
UNION ALL
SELECT 'destination_table' as tbl_name, D.PK, D.column_list
FROM destination_table AS D
) AS alias_table
GROUP BY PK, column_list
HAVING COUNT (*) = 1
ORDER BY PK

-> tbl_name is just additional column name to display the name of tables you want to compare. These are source_table and destination_table
-> PK is identity name of source_table and destination_table
-> column_list is the list of column you want to compare
-> The MIN aggregate on table_name is just arbitrary. It is used because we only returns group of rows in which there was no consolidation with GROUP BY.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.