I have a query that needs to pull data from two tables based on criteria from those two and a third table. The issue I'm having is with the WHERE part of the query.
Here's the basic query. It works correctly for the result that I need.
SELECT county.*, ob.* FROM oshs_businesses AS ob
LEFT JOIN oshs_services_counties AS county ON ob.bus_id = county.svc_cnt_busid
LEFT JOIN oshs_services AS svc ON ob.bus_id = svc.svc_busid
WHERE svc.svc_cat = ".$searchcat."
AND ob.bus_state = '".$searchstate."'
AND county.svc_cnt_sctid = '".$searchcountyid."'
ORDER BY ob.bus_name
I need to now make one modification to the WHERE part of the query. I need the records:
Criteria 1
WHERE svc.svc_cat = ".$searchcat."
Criteria 2 (either of two conditions)
--- Either Part 1 ---
[INDENT]AND ob.bus_state = '".$searchstate."'
AND county.svc_cnt_sctid = '".$searchcountyid."' [/INDENT]
--- Or Part 2---
[INDENT]ob.bus_range = 1[/INDENT]
In other words, I want to keep the first criteria. For criteria 2, it can be either part 1 or part 2 but not both.
How do I form this query?