Can we compare values of two columns in a WHERE clause?


#1

Question

Can we compare values of two columns in a WHERE clause?

Answer

Yes, within a WHERE clause you can compare the values of two columns.

When comparing two columns in a WHERE clause, for each row in the database, it will check the value of each column and compare them.

Example

/* 
This will return all rows where the value in the 
x column is greater than the y column value. 
*/

SELECT x, y
FROM coordinates
WHERE x > y;