正在针对不存在的特定记录从 MySQL 中检索数据
Retrieving Data From MySQL Against Specific Record Already Not Exist
实际上,我对从 MySql DB
获取数据感到困惑。我有两个表 Room
和 Dentist
。在 Dentist Form
中,我正在使用 Combobox
来显示 RoomID
,如下图红色圆圈所示。在那个 Combobox
中,我只想显示那些没有 DentistID
的 RoomID
。 MySql Query
是什么。
我的DataBase
两张桌子的照片Room & Dentist
如下。在 Room Table
InchargeID
和 Dentist Table
中,DentistID
都是相同的,但名称不同。
假设您存储房间的 table 被命名为 rooms
,并且 InchargeID
字段允许空值,这应该足够了:
select RoomID from rooms where InchargeID is null;
这是一个SQLFiddle,您可以在其中进行测试。
您需要对表使用连接,还需要将 is null
与您要应用 'null' 条件的列名一起使用。您可以在下面的查询中找到 Room
和 Dentist
中 DentistID 为空的所有数据。
select Room.*, Dentist.* from Dentist right join Room on Dentist.RoomID = Room.RoomID where Dentist.DentistID is null;
根据你的问题,我认为你需要的房间 ID 没有分配给任何牙医。所以你可以从下面的查询中得到它:
SELECT Room.RoomID FROM Room WHERE Room.RoomID NOT IN (SELECT Dentist.RoomID FROM Dentist);
实际上,我对从 MySql DB
获取数据感到困惑。我有两个表 Room
和 Dentist
。在 Dentist Form
中,我正在使用 Combobox
来显示 RoomID
,如下图红色圆圈所示。在那个 Combobox
中,我只想显示那些没有 DentistID
的 RoomID
。 MySql Query
是什么。
我的DataBase
两张桌子的照片Room & Dentist
如下。在 Room Table
InchargeID
和 Dentist Table
中,DentistID
都是相同的,但名称不同。
假设您存储房间的 table 被命名为 rooms
,并且 InchargeID
字段允许空值,这应该足够了:
select RoomID from rooms where InchargeID is null;
这是一个SQLFiddle,您可以在其中进行测试。
您需要对表使用连接,还需要将 is null
与您要应用 'null' 条件的列名一起使用。您可以在下面的查询中找到 Room
和 Dentist
中 DentistID 为空的所有数据。
select Room.*, Dentist.* from Dentist right join Room on Dentist.RoomID = Room.RoomID where Dentist.DentistID is null;
根据你的问题,我认为你需要的房间 ID 没有分配给任何牙医。所以你可以从下面的查询中得到它:
SELECT Room.RoomID FROM Room WHERE Room.RoomID NOT IN (SELECT Dentist.RoomID FROM Dentist);