SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Join table only when needed

    Hi guys

    I have a bit of a issue


    I am displaying rows from my database like this

    PHP Code:
    SELECT FROM dates INNER JOIN bookings on bookings.Dates_ID=dates.Dates_ID 
     WHERE dates
    .Dates_ID='$dates_id' ORDER BY Start_Time DESC 

    10:00 BOOKED
    11:00 Add Booking
    12:00 Add Booking
    13:00 Add Booking
    14:00 BOOKED
    15:00 Add Booking
    16:00 Add Booking

    The issue is only the rows which say BOOKED can join up with a certain table (customers) in my database

    As when it says BOOKED there is a value in the customer_id field


    PHP Code:
    SELECT FROM dates INNER JOIN bookings on bookings.Dates_ID=dates.Dates_ID  INNER JOIN customers ON customers.Customer_ID bookings.Customer_ID
     WHERE dates
    .Dates_ID='$dates_id' ORDER BY Start_Time DESC 
    Which displays the table like this

    10:00 BOOKED CHRIS
    14:00 BOOKED David
    How can I display all the rows even if the customers table is empty

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Use a LEFT JOIN


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
  •