我有三张表,如下截图所示:
但是,当我要执行以下查询时,即使这三个表中都有数据,也不会得到任何结果:
下面是生成的代码:

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

最佳答案

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以更好地了解使用什么
如果性能是一个问题,还有其他一些方法。

关于sql - 查询三个表什么都不输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15467556/

10-13 09:19