I'm quite new to SQL and am facing the following problem. Consider we have a table with two columns:
A B
10 20
NULL 15
25 10
50 30
NULL 100
What I need is to select rows which satisfy the following conditions:
either
1) A is NULL
or
2) A < B
Which means, as a result I want to see such table:
A B
10 20
NULL 15
NULL 100
I tried to use the following query:
SELECT * FROM mytable
WHERE A < B OR A is NULL
But it seems like it doesn't work the way I supposed it to.
How should a correct query look like? Thank you!
What I queried was: "SELECT * FROM table WHERE ...some conditions on other columns... AND A IS NULL OR A < B"
You should put the OR comparison in parenthesis:
...AND (A IS NULL OR A < B)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With