SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to use 'OR' in this query

    Hi folks,
    I'm trying to do a little search script for our eyeglasses frames website and one of the fields in the database is 'gender'. We have frames that are specifically male and female and some that are unisex, so in my search query I want to be able to search for male and unisex or female and unisex, among other things. Is there a way I can structure the query, maybe with a subquery on gender or something, that will keep the 'OR' for the gender from messing up the rest of the query? I'm not very good at complicated queries yet. Here is my query as it exists so far:
    Code:
    SELECT * FROM ma_frames 
    WHERE ma_frames.brandid <= 12 
    AND frametypeid = $frametype 
    AND genderid = $gender OR genderid = 3 
    AND colourid = $colour
    Thanks!

  2. #2
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    WHERE ma_frames.brandid <= 12
    AND frametypeid = $frametype
    AND genderid IN ($gender, 3)
    AND colourid = $color
    Alternatively, just wrap the two genderid clauses in brackets so the operator precedence doesn't get messed up.
    Adrian Schneider - Web Developer

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works great. Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •