Last active
January 6, 2020 20:44
-
-
Save KrashLeviathan/7f50588e9f5f4216d555a12fb2af3677 to your computer and use it in GitHub Desktop.
Check to see if two SELECT statements are equivalent in SQL
This file contains hidden or 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
-- Found this in the following StackOverflow post and found it useful on multiple occasions | |
-- https://stackoverflow.com/questions/5727882/check-if-two-selects-are-equivalent | |
WITH query1 AS | |
( | |
-- Copy/paste SELECT statement here | |
), | |
query2 AS | |
( | |
-- Copy/paste SELECT statement here | |
) | |
select * from ( | |
(select * from query1 MINUS select * from query2) | |
UNION ALL | |
(select * from query2 MINUS select * from query1) | |
) | |
; | |
-- This will result in all rows that are returned by only one of the queries |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link to the original StackOverflow answer: https://stackoverflow.com/a/5728044/10393763