简体   繁体   English

用“ not in”子句连接两个以上的表

[英]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? 您能告诉我在哪里可以将FK_roomTypesID,FK_BedTypeID和FK_roomViewsID表加入其中吗? All of the FK are on different tables from the primary. 所有FK与主数据库位于不同的表上。

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子句中定义join ,因此应将上面的代码修改为:

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. 请注意,您没有提供太多信息,所以我猜这里是您的table名和column名。 Also, note, that I did not select any new columns . 另外,请注意,我没有选择任何新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. 最后,请注意,如果问题适用于您的情况,则需要解决歧义,方法是将您的columns称为table的列。 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. 我没有对joins使用inner关键字,因为默认情况下joininner的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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