I want to retrieve the row if any of the 3 integer field in a row is greater than zero. All the field has default value of zero.
Which of the following query is better?
-- Query 1
SELECT * FROM my_table WHERE number_A > 0 OR number_B > 0 OR number_C > 0
-- Query 2
SELECT * FROM my_table WHERE (number_A + number_B + number_C) > 0
While checking the execution time both the query gives same numbers and the result data of the query is exactly the same.
number_A
satisfies the condition; while in the second query, the SGBD will have to check the values of the 3 parameters and sum them in all cases. \$\endgroup\$WHERE (number_A, number_B, number_C) > (0, 0, 0)
\$\endgroup\$