Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if two "select"s are equivalent

Tags:

sql

select

oracle

Is there a way to check if two (non-trivial) select are equivalent?

Initially I was hoping for a formally equivalence between two selects, but the answers in proving-sql-query-equivalency stop me.

For my actual need I can just check if the (actual) results of two selects are the same.

like image 832
Vito De Tullio Avatar asked Apr 20 '11 09:04

Vito De Tullio


People also ask

How compare two SQL SELECT statements?

By using UNION, UNION ALL, EXCEPT, and INTERSECT, we can compare two queries and get the necessary output as per our requirement. Given examples are simple to follow, we can have complex queries and can apply the mentioned constructs in them and can compare.

How do you compare two queries performance?

Run the queries and compare logical reads for the various tables and execution times. @CombatCaptain You can also stack the comparing queries together in SSMS and press CTRL+M (include actual execution plan) and then F5 .

How do I check if two columns are equal in SQL?

In SQL, problems require us to compare two columns for equality to achieve certain desired results. This can be achieved through the use of the =(equal to) operator between 2 columns names to be compared.


1 Answers

If you want to compare the query results try the following:

(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.

like image 74
HAL 9000 Avatar answered Sep 24 '22 00:09

HAL 9000