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