简体   繁体   中英

Join more than two tables with “not in” clause

Can you please show me where I can INNER JOIN the tables for the FK_roomTypesID, FK_BedTypeID and FK_roomViewsID? All of the FK are on different tables from the primary.

MySqlDataAdapter da = new MySqlDataAdapter("SELECT RoomNo, RoomBedsNo, 
    RoomSmoking, RoomMiniBar,RoomKitchen,RoomFirePlace,RoomBalcony, RoomVeranda,
    RoomGarden, RoomEntrance, RoomAirCondition, RoomTV, FK_roomTypesID, 
    FK_BedTypeID, FK_roomViewsID FROM tblrooms WHERE roomsID NOT IN(SELECT FK_roomsID
    FROM tblbooking WHERE '" + arrdate + "' < checkOutDate AND '" + depdate + "' > 
    checkInDate)", conn);

You have the following part in your query:

FROM tblrooms

You define your join s in your FROM clause, therefore you should modify the code above to something like:

FROM tblrooms
join tblroomtypes
on tblrooms.FK_roomTypesID = tblroomtypes.roomTypesID
join tblbedtypes
on tblrooms.FK_bedTypesID = tblbedtypes.bedTypesID
join tblroomviews
on tblrooms.FK_roomViewsID = tblroomviews.roomViewsID

Note, that you did not give too much information, so I am guessing your table and column names here. Also, note, that I did not select any new columns . Finally, note, that you need to resolve ambiguity if the problem is applicable to your case by referring to your columns as table 's columns. And format your code, it is difficult to read it. I did not use the inner keyword for the joins , because join is inner by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM