Scenario 1: Following query displays whether the differences exists or not.

SELECT IF(COUNT(1)>0,’Differences’,’No Differences’) Comparison FROM
(

SELECT
column_name,ordinal_position,
data_type,column_type,COUNT(1) rowcount
FROM information_schema.columns
WHERE table_schema=DATABASE()
AND table_name IN (‘products‘,’pub_products‘)
GROUP BY
column_name,ordinal_position,
data_type,column_type
HAVING COUNT(1)=1

) A;

Scenario 2: Following query displays differences of columns found between two tables.

SELECT column_name,ordinal_position,data_type,column_type FROM
(

SELECT  column_name,ordinal_position,
data_type,column_type,COUNT(1) rowcount
FROM information_schema.columns
WHERE table_schema=DATABASE()
AND table_name IN (‘products‘,’pub_products‘)
GROUP BY
column_name,ordinal_position,
data_type,column_type
HAVING COUNT(1)=1

) A;

Advertisements