I have the following query and I am wondering what is wrong with it. It is not filtering on the date range I have chosen. I have tried reordering my WHERE clause, it doesn’t seem to work.
SELECT UNIT_NUMBER, ORG_CREATED_ACTIVE_DATE, ORG_TYPE
FROM TABLE_NAME
WHERE ORG_TYPE = 'Ward'
OR ORG_TYPE = 'Branch'
OR ORG_TYPE = 'Stake'
OR ORG_TYPE = 'District'
AND ORG_CREATED_ACTIVE_DATE BETWEEN '02-JUL-23' AND '18-DEC-23';
>Solution :
You are using both AND and OR inside the WHERE.
SELECT UNIT_NUMBER, ORG_CREATED_ACTIVE_DATE, ORG_TYPE
FROM TABLE_NAME
WHERE (ORG_TYPE = 'Ward'
OR ORG_TYPE = 'Branch'
OR ORG_TYPE = 'Stake'
OR ORG_TYPE = 'District')
AND ORG_CREATED_ACTIVE_DATE BETWEEN '02-JUL-23' AND '18-DEC-23';