labels: mysql , script , compare , differences , fields
SET @database1 = "eshopkat_demo",
@table1 = "cs_categories",
@database2 = "katoik_cs4shop",
@table2 = "cscart_categories";
/* If function ANY_VALUE() does not exist, just remove it*/
SELECT t.COLUMN_NAME,t.COLUMN_TYPE,ANY_VALUE(t.db) db FROM (SELECT `COLUMN_NAME`,`COLUMN_TYPE`,@database1 db
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`=@database1 AND `TABLE_NAME`=@table1
UNION ALL
SELECT `COLUMN_NAME`,`COLUMN_TYPE` ,@database2 db FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`=@database2 AND `TABLE_NAME`=@table2) t
GROUP BY t.COLUMN_NAME,t.COLUMN_TYPE HAVING COUNT(*) = 1 ORDER BY t.COLUMN_NAME;