I am using PostgreSQLwith VB.NET/ODBC and have to construct a bit complex query string.
This is simplified version:
SELECT dtbl_id, idx, name, meas, code, year FROM mytable
WHERE name ILIKE ‘nemo%’ <- edited
AND (dtbl_id BETWEEN 1 AND 9999)
OR (dtbl_id BETWEEN 15000 AND 19999) ORDER BY name
I also try:
AND (dtbl_id BETWEEN 1 AND 9999)
AND (dtbl_id BETWEEN 15000 AND 19999) ORDER BY name
Where I try to get names starting with “nemo” but only if they have indexes between 1 and 9999 and indexes between 15000 AND 19999.
In both cases I dont get desired result (if any).
What is wrong with my query?
Try:
Details here.
The mistake –
ORhas lower priority thenAND. So, your firstWHEREclause reads like:Another mistake (as pointed out by Edmund) – to get names starting with
nemoyou needILIKE 'nemo%'.