例如,我有2个彼此有关系的表。 room_directory.id 和 booked_room.room_id
id
room_number
id
booking_id
room_id
如何编写只选择 room_directory 中 registered_room 表中不存在的会议室的查询?
答案 0 :(得分:0)
select * from room_directory where id not in (select room_id from booked_room)
答案 1 :(得分:0)
select * from room_directory r where r.id not in (select room_id from booked_room b where r.id = b.room_id);
或
SELECT * FROM room_directory r WHERE NOT EXISTS (SELECT * from booked_room b WHERE r.id = b.room_id);