I have views in two databases V1 and V2 with same set of columns col1, col2.
Now I would like to know if they contains identical rows. In this context I have gone through this post: SQL compare data from two tables.
Following this I am running the below query:
select * from v1.A
minus
select * from v2.A;
But I am getting the below error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select * from v2.A' at line 3
I am not getting any clue regarding how to fix this error.
You can simulate
minuswhich is not supported in MySql withNOT EXISTS:I use the NULL-safe equal operator
<=>instead of just=just in case there arenulls that need to be compared.But if this query does not return any results it does not mean that the 2 views return the same rows, because
v1.Amay return a subset of the rows returned byv1.B.So you also need:
and maybe better a
UNION ALLof the 2 queries to be sure: