2

I have three tables as shown in the screenshot below: dataset

But when I want to perform the following query, i get no results, even though there is data in all three tables:

query

Here is the generated code:

SELECT Clients.ClientID, Clients.FirstName, Clients.Surname, Clients.Internal, Clients.Organisation, Clients.LandlineNo, Clients.MobileNo, Clients.Address1, Clients.Town, 
              Clients.Postcode, Clients.Email, Clients.NHS, Clients.PurchaseOrderNumber, Bookings.Date, Bookings.Timebegan, Bookings.Timefinished, Bookings.Price, 
              Bookings.Repeats, Bookings.Rweeks, Bookings.Rdays, Bookings.Rmonths, Bookings.Occurrences, Rooms.Roomname
FROM     Clients INNER JOIN
              Bookings ON Clients.ClientID = Bookings.ClientID INNER JOIN
              Rooms ON Bookings.RoomID = Rooms.RoomID
1
  • 6
    Since you are using inner joins all of the tables need to contain data. Try changing the joins to left outer joins and see if you get the results you are looking for.
    – Mark Kram
    Mar 17, 2013 at 23:31

1 Answer 1

1
Try

SELECT *
FROM     Clients LEFT OUTER JOIN
         Bookings ON Clients.ClientID = Bookings.ClientID 
         LEFT OUTER JOIN Rooms ON Bookings.RoomID = Rooms.RoomID

See Visual Explanation of SQL Join to better understand what to use

There are also some other approaches if performance is an issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.