我有三个表,如下面的屏幕截图所示:
但是当我想执行以下查询时,即使所有三个表中都有数据,我也没有得到任何结果:
以下是生成的代码:
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
答案 0 :(得分:1)
Try
SELECT *
FROM Clients LEFT OUTER JOIN
Bookings ON Clients.ClientID = Bookings.ClientID
LEFT OUTER JOIN Rooms ON Bookings.RoomID = Rooms.RoomID
请参阅Visual Explanation of SQL Join以更好地了解使用方法
如果性能问题,还有其他一些方法。