[英]how to get data from a table which data is not available in joined table in cakePHP
I am using cakePhp 3.6, I have two table. 我正在使用cakePhp 3.6,我有两个表。 Both are joined. 两者都加入了。 In one table I have some token
table name is codes
and on another table I have stored some code
for some venue. 在一个表中,我有一些token
表名称是codes
,在另一个表中,我存储了一些场所的code
。 Table name is venues_codes
. 表格名称是venues_codes
。
Like I have 10 code
in codes
table. 就像我在codes
表中有10个code
。 And in venues_codes
table 5 code
is stored for some vanue. 而在venues_codes
表5 code
存储一些vanue。 This is the structure for venues_codes
table. 这是venues_codes
表的结构。 id venue_id code_id
. id venue_id code_id
。 Here venue_id
is coming from another table. 在这里, venue_id
来自另一个表。 It is not my concern now. 现在不用担心了。 I just want to get the rest five code
from codes
table that is not available in venues_codes
table. 我只想从venues_codes
codes
表中不可用的codes
表中获取其余五个code
。
This is how I have tried, but it is only fetching token
that is available in both table. 这是我尝试过的方法,但是只能获取两个表中都可用的token
。
$this->loadModel('VenueCodes');
$this->loadModel('Codes');
$query = $this->VenueCodes->find()
->contain(['Codes'])
->select(['id','code_id']);`
I am working with CakePHP. 我正在使用CakePHP。 But if anyone can help me with the normal sql logic, that also will be helpful for me. 但是,如果有人可以用常规的sql逻辑帮助我,那也将对我有所帮助。
这应该为您提供所有未连接到场所的代码:
$codes = $this->Codes->find()->notMatching('Venues');
纯mysql查询如下所示:
SELECT code FROM codes WHERE code NOT IN (SELECT code_id FROM venues_codes);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.