[英]Where-clause with left joined tables
I have two tables: products and products_actions. 我有两个表:products和products_actions。
When the user clicks away a product, I want this action to be stored in products_actions. 当用户单击某个产品时,我希望将此操作存储在products_actions中。 The field has_removed
will be 1 then. 那么字段has_removed
将为1。
I would like to present to the user only those products that he has not clicked away. 我只想向用户展示那些他没有点击的产品。
Currently I have the following entries in my tables: 当前,我的表中包含以下条目:
Table "products": 表“产品”:
id: 1
name: Product 1
id: 2
name: Product 2
id: 3
name: Product 3
Table "products_actions": 表“ products_actions”:
id: 1
id_product: 2
has_removed: 1
If the user has not removed a product from his page so far, there will be no corresponding entry in the products_actions table. 如果到目前为止用户尚未从其页面上删除产品,那么products_actions表中将没有相应的条目。
So my query is: 所以我的查询是:
$qb->select('p')
->leftJoin(
'ProductsActions',
'pa',
'WITH',
'pa.idProduct = p.id'
)
->where('pa.hasRemoved != 1');
How do I achieve that my query aboves delivers "Product 1" and "Product 3" as entries? 如何实现上述查询提供“产品1”和“产品3”作为条目?
I am not entirely clear what you need. 我不清楚您需要什么。 I guess you are talking probably like this : 我猜你可能在这样说:
select * from products where id not in (select id_product from products_actions where hasRemoved = 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.