Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@KrashLeviathan
Last active January 6, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KrashLeviathan/7f50588e9f5f4216d555a12fb2af3677 to your computer and use it in GitHub Desktop.
Save KrashLeviathan/7f50588e9f5f4216d555a12fb2af3677 to your computer and use it in GitHub Desktop.
Check to see if two SELECT statements are equivalent in SQL
-- 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
@KrashLeviathan
Copy link
Author

Link to the original StackOverflow answer: https://stackoverflow.com/a/5728044/10393763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment