SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inner join help please

    Hello,

    Wondering if anyone could help me with a inner join query which is confusing me

    Code:
    SELECT photographic_schedule.user_id, photographic_users.name, photographic_schedule.appointment_type, photographic_schedule.live, photographic_schedule.the_date, photographic_schedule.event_begin_time, photographic_schedule.event_end_time
    FROM photographic_schedule
    INNER JOIN photographic_users ON photographic_schedule.user_id = photographic_users.user_id
    WHERE photographic_schedule.appointment_type =98
    OR photographic_schedule.appointment_type =99
    AND photographic_schedule.live =1
    AND photographic_schedule.the_date = '2011-03-17'
    My problem being this part AND photographic_schedule.the_date = '2011-03-17'. Which it seems to ignore If I change this to any date, ie 2011-03-18, 2011-11-21 it still returns all results in my database regardless of the date?

    Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    When you start using OR and AND in the WHERE conditions, it's better to use parentheses to avoid unwanted results:
    Code:
    WHERE 
        (   photographic_schedule.appointment_type =98
         OR photographic_schedule.appointment_type =99 )
    AND photographic_schedule.live =1
    AND photographic_schedule.the_date = '2011-03-17'
    In this case you could use IN instead of the two conditions with OR:
    Code:
    WHERE photographic_schedule.appointment_type IN (98, 99)
    AND   photographic_schedule.live =1
    AND   photographic_schedule.the_date = '2011-03-17'


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
  •