繁体   English   中英

左连接表的子句

[英]Where-clause with left joined tables

我有两个表:products和products_actions。

当用户单击某个产品时,我希望将此操作存储在products_actions中。 那么字段has_removed将为1。

我只想向用户展示那些他没有点击的产品。

当前,我的表中包含以下条目:

表“产品”:

id: 1
name: Product 1

id: 2
name: Product 2

id: 3 
name: Product 3

表“ products_actions”:

id: 1 
id_product: 2
has_removed: 1

如果到目前为止用户尚未从其页面上删除产品,那么products_actions表中将没有相应的条目。

所以我的查询是:

$qb->select('p')
            ->leftJoin(
                'ProductsActions',
                'pa',
                'WITH',
                'pa.idProduct = p.id'
            ) 
            ->where('pa.hasRemoved != 1');

如何实现上述查询提供“产品1”和“产品3”作为条目?

我不清楚您需要什么。 我猜你可能在这样说:

select * from products where id not in (select id_product from products_actions where hasRemoved = 1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM