Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

element is equal one of values sql server

Put parentheses around the "OR"s:
SELECT ads.*, location.county 
FROM ads
LEFT JOIN location ON location.county = ads.county_id
WHERE ads.published = 1 
AND ads.type = 13
AND
(
    ads.county_id = 2
    OR ads.county_id = 5
    OR ads.county_id = 7
    OR ads.county_id = 9
)

Or even better, use IN:

SELECT ads.*, location.county 
FROM ads
LEFT JOIN location ON location.county = ads.county_id
WHERE ads.published = 1 
AND ads.type = 13
AND ads.county_id IN (2, 5, 7, 9)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #element #equal #values #sql #server
ADD COMMENT
Topic
Name
3+5 =