我有这个连接sql语句,但我似乎无法得到我想要的输出

时间:2016-09-06 12:14:08

标签: sql join

SELECT * FROM tblcheck as ch 
INNER JOIN 
rooms as r on ch.room_id = r.room_id
INNER JOIN
roomtype as c on c.RoomType_id = r.RoomType_id
INNER JOIN
guest as g on g.room_id = ch.room_id

我想要的输出是显示这个

Guest Name || Room Name || Roomtype || Check-in Date and Time

但我在访客名称中有错误。它显示了访客表中的每个人:(请帮助我

1 个答案:

答案 0 :(得分:0)

如果我们知道表结构,会更容易提供帮助。到返回的列,您可以选择如下所示:

SELECT
    g.name
   ,r.name
   ,r.roomtype
   ,ch.checkInDate
   ,ch.time
FROM
    tblcheck as ch 
INNER JOIN 
    rooms as r on ch.room_id = r.room_id
INNER JOIN
    roomtype as c on c.RoomType_id = r.RoomType_id
INNER JOIN
    guest as g on g.room_id = ch.room_id