簡體   English   中英

SQL如何從另一個表中不存在的表中選擇

[英]Sql how to select from a table that does not exist in another table

例如,我有2個相互關聯的表。 room_directory.idbooked_room.room_id

room_directory

id
room_number

booked_room

id
booking_id
room_id

如何編寫查詢,僅從room_directory中選擇booked_room表中不存在的房間

select * from room_directory where id not in (select room_id from  booked_room)

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM