[英]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.