Reputation: 4642
I have a database that contains Businesses
and I want to query all of the businesses that have a specific name in them, within a series of postcodes.
For example:
business_name
= KFC
postcode
= `[N1, N17, N18, BN1]
I have tried the following query:
SELECT * FROM businesses WHERE business_name = 'KFC' AND postcode LIKE '%N1%' OR postcode LIKE '%N17%' OR postcode LIKE '%N18%' OR postcode LIKE '%BN1'
The issue is that it's bringing back businesses that have this postcode, but have nothing to do with KFC
.. Can anyone suggest a reason for this and what I should be doing?
Upvotes: 0
Views: 54
Reputation: 3592
Try this way:
SELECT * FROM businesses WHERE business_name = 'KFC' AND (postcode LIKE '%N1%' OR postcode LIKE '%N17%' OR postcode LIKE '%N18%' OR postcode LIKE '%BN1')
Upvotes: 3