[英]How do I iterate all rows from two tables connected by foreign key into a single table in PHP, CodeIgniter, MySQL
[英]How do I select only rows that don't have a corresponding foreign key in another table in MySQL?
我有3張桌子:
“照片”和“日歷”中都有一個“ listing_id”列,每個“列表”都有一個“照片”。 但是我只想選擇在“ calendar”表中沒有匹配項“ listing_id”的行。
我不確定我說的是否正確,但是任何幫助將不勝感激。 如果有人可以告訴我CodeIgniter語法,那就更好了。
這將產生calendar.free_date值的列表,由於列表表中不存在與它們關聯的listing_id值,因此不應返回這些值。
select free_date from calendar c
where not exists (select * from listing
where listing_id = c.listing_id);
應作為SQL查詢工作。 不確定CI語法。 抱歉!
SELECT * FROM清單WHERE listing_id不在(SELECT清單FROM日歷)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.