List:General Discussion« Previous MessageNext Message »
From:Reindl Harald Date:January 2 2012 3:38pm
Subject:Re: Beginner question
View as plain text  

Am 02.01.2012 16:33, schrieb Biz-comm:
> Thanks for any assistance.
> 
> Web page  that needs a sort of all records with a specific state, set to "show", and
> if it exists in one of 4 categories.
> 
> 
> Using this:
> 
> SELECT * 
> FROM listings
> WHERE listing_state = 'DC' 
> AND listings.listing_show ='y'  
> AND  listings.cat1 = 23  OR listings.cat2 = 23 OR listings.cat3 = 23 
> 
> 
> Gives up 2 records in the state of DC, set to show, and are listed in cat1.
> However, it also gives up 2 records in the state of VA, set to show, but are listed
> in cat2 (not in 1).
> Any assistance most appreciated.

basic math
how should mysql know that the OR-clauses are meant not standalone?

SELECT *
FROM listings
WHERE listing_state = 'DC'
AND listings.listing_show ='y'
AND (listings.cat1 = 23  OR listings.cat2 = 23 OR listings.cat3 = 23)


Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Thread
Beginner questionBiz-comm2 Jan
  • Re: Beginner questionReindl Harald2 Jan
  • Re: Beginner questionMike OK2 Jan
    • Re: Beginner questionBiz-comm2 Jan