选择3个内连接的Distinct Column

时间:2013-12-20 12:47:15

标签: mysql sql select group-by distinct

我想在这个sql语句中选择不同的RoomName,我不知道在这个sql语句中放置不同的地方。

SELECT Distinct
R.RoomID,R.RoomName,RT.RTypeName,RT.RTypePrice,RB.RBedName,RB.RBedPrice,
G.GalName,G.GalPath

FROM tbRoom as R
   INNER JOIN tbRoomType as RT ON R.RTypeID = RT.RTypeID
   INNER JOIN tbRoomBed as RB ON R.RBedID = RB.RBedID
   INNER JOIN tbGallery as G ON R.GalID = G.GalID
WHERE R.RoomID NOT IN(
    SELECT RD.RoomID FROM tbReservationDetail as RD WHERE
    RD.ArrivalDate <= '$dep' AND RD.DepartureDate >= '$arr' AND R.RoomID =
    RD.RoomID
)

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT R.RoomID,R.RoomName,RT.RTypeName,RT.RTypePrice,RB.RBedName,RB.RBedPrice, G.GalName,G.GalPath
FROM tbRoom AS R
INNER JOIN tbRoomType AS RT ON R.RTypeID = RT.RTypeID
INNER JOIN tbRoomBed AS RB ON R.RBedID = RB.RBedID
INNER JOIN tbGallery AS G ON R.GalID = G.GalID
WHERE R.RoomID NOT IN(
    SELECT RD.RoomID 
    FROM tbReservationDetail AS RD 
    WHERE RD.ArrivalDate <= '$dep' AND RD.DepartureDate >= '$arr' AND R.RoomID = RD.RoomID
)
GROUP BY R.RoomName;