Hi,
Is there a logic to check if two Sql Queries would yield same result.
For example:
We know that
Query1: Select Name, Cadre, Age, Salary FROM myTable WHERE Name ='Alice' AND Cadre in ('A','B','C','D') and AGE <=35 and Salary >=40000
Query2: SELECT Name,Cadre, Age, Salary FROM myTable WHERE Name='Alice' AND (Cadre ='A' or Cadre ='B' or Cadre = 'C' or Cadre='D') AND AGE<=35 AND SALARY>=40000
- would yield SAME result if both are run on the SAME table.
Now is there a way to find this WITHOUT ACTUALLY RUNNING THE QUERIES ON THE TABLES and comparing their results ?
Meaning, I want to develop a function which would be used like:
if isEquivalent(Query1,Query2) then
Msgbox("Both the functions would return same result")
else
Msgbox("They are not equivalent queries")
end if
Note:
The above function isEquivalent must NOT make use of any table to check this since we (humans) do not need a table to check that they will yield the same result ! Looking at the query itself we know that it will give the SAME result when run on the SAME table...
Ps. help !
Thanks.