it's actually caused by you mixing ANDs and ORs
Originally Posted by gwpaul
they work like addition and multiplication
for example, what is 1+2*3 ? is it 1+(2*3) or (1+2)*3 ?
to mix ANDs and ORs, always use parentheses to ensure you get exactly the logic you want
also, another thing that is affecting your results is this --
the attorney's firm_id is never going to be equal to that character string
attorney.firm_id = 'law_firm.firm_id'
let's revise the query to avoid the ORs problem...
finally, you have a repeating group in the law_firm table, those 5 county columns -- these should be normalized into a separate table because as they are now, they will slow down this query
ON attorney.firm_id = law_firm.firm_id
WHERE '$_POST[county]' IN ( law_firm.county_0
, law_firm.county_4 )
AND law_firm.state = '$state'
AND law_firm.status = '2'