Last active
January 5, 2017 14:16
-
-
Save Chetan496/b58dd67f4997f22dc00a4eeb8f7dccf3 to your computer and use it in GitHub Desktop.
Find if two tables are containing identical data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT 1 FROM ( | |
SELECT * FROM table1 | |
UNION ALL | |
SELECT * FROM table2 | |
) t | |
GROUP BY col1, col2, col3 | |
HAVING count(*) = 1 | |
LIMIT 1 | |
List all the columns in GROUP BY to compare the entire table. | |
If the result is an empty set, the two tables are identical. | |
to see which rows differ: | |
SELECT * FROM ( | |
SELECT 'DAL_ObjectHistory_View' tname,Status, Id, InstanceId, CDTName, Namespace, CDTNameWithNamespace, OldValue, OldValueReadMore, NewValue, NewValueReadMore, | |
parentVariableName, instanceVariableId, ProcessModelId, ModifiedBy, ModifiedDateTime FROM DAL_ObjectHistory_View | |
UNION ALL | |
SELECT 'DAL_ObjectHistory_View2' tname, Status, Id, InstanceId, CDTName, Namespace, CDTNameWithNamespace, OldValue, OldValueReadMore, NewValue, NewValueReadMore, | |
parentVariableName, instanceVariableId, ProcessModelId, ModifiedBy, ModifiedDateTime FROM DAL_ObjectHistory_View2 | |
) t | |
GROUP BY Status, Id, InstanceId, CDTName, Namespace, CDTNameWithNamespace, OldValue, OldValueReadMore, NewValue, NewValueReadMore, | |
parentVariableName, instanceVariableId, ProcessModelId, ModifiedBy, ModifiedDateTime | |
HAVING count(*)=1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment