SQL Where Query Help

Discussion in 'MySQL' started by LazyD, Apr 12, 2007.

  1. #1
    Hello all, I have a MySQL query I need help with...

    Essentially I have a calender with names, events, etc. What I would like to do in addition to viewing it normally is to search the calendar by name. The catch is there are 2 events per a day and 2 names per an event.

    My current SQL statement looks like this:
    $query2 = "SELECT *, DATE_FORMAT(sEventStart, '%l:%i %p') as sEventStartClean, DATE_FORMAT(sEventEnd, '%l:%i %p') as sEventEndClean FROM schedule WHERE sDate='$sDate' ORDER BY sRig ASC
    PHP:
    This works as it is...However, if I do the SQL Query I thought would work...
    SELECT *, DATE_FORMAT(sEventStart, '%l:%i %p') as sEventStartClean, DATE_FORMAT(sEventEnd, '%l:%i %p') as sEventEndClean FROM schedule WHERE sName1='$SearchName' OR sName2='$SearchName' AND sDate='$sDate' ORDER BY sRig ASC
    PHP:
    It displays all funky in the sense that its selecting all of the listings where sName1 and sName2 are equal to the $Searchname regardless of the date in addition to listings where sDate = $sDate

    I would like it to select it so EITHER sName1 or sName2 are equal to $SearchName AND sDate=$sDate
     
    LazyD, Apr 12, 2007 IP
  2. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nevermind - Fixed

    I found the solution in the UNION function
     
    LazyD, Apr 12, 2007 IP