【发布时间】:2014-08-03 17:03:00
【问题描述】:
这些表格是:
units (id,...) // approx' 10,000 units
contracts(id, unit_id, active, ...) // approx 50,000 records
我想获得所有没有附加合同的单位(和contracts.active=true)。
我的想法是:
使用NOT IN:
从单位中选择 *
where id NOT IN(从contracts.active = true的合约中选择unit_id)
或者:
select * from units u
left join contracts c
on c.unit_id = u.id
where c.unit_id is null
而且,如果有在蛋糕中做的本地方法,请告诉我灯:)
谢谢
【问题讨论】:
标签: mysql join cakephp-1.3