此查询出了什么问题
SELECT `product`.`id`, `title` AS `text` FROM `product`
LEFT JOIN `productlang` ON product.id=productlang.product_id
LEFT JOIN `new_product` ON product.id=new_product.product_id
WHERE (`product`.`id` <> `new_product`.`product_id`)
AND (`title` LIKE '%nik%')
AND (`language`='bg')
LIMIT 20
目的是从product
表中不存在{{1}的id
表中获得所有产品(new_product
是相关列)。 }}部分应该可以解决问题。我哪里不好?谢谢!
答案 0 :(得分:1)
Left Join
,请确保在Where
子句中指定了Left Join
右侧表上的On
条件。否则,这会限制您的结果集。IS NULL
。请尝试以下操作:
SELECT p.id,
pl.title AS `text`
FROM product AS p
LEFT JOIN productlang AS pl
ON p.id = pl.product_id AND
pl.title LIKE '%nik%' AND
pl.language = 'bg'
LEFT JOIN new_product AS np
ON p .id = np.product_id
WHERE np.product_id IS NULL
LIMIT 20