0

我有简单的mysql查询:

SELECT product.user_id, product.type, product.body, product.created, product.id, product.url, product.name, product.price, images.src 
FROM xn_product AS product 
LEFT JOIN xn_images AS images ON product.id = images.item_id 
WHERE product.active = '1' AND images.type = 'product' AND product.promoted = '1' AND images.main = '1' AND product.url = '". $url "'

我有问题。当在 images.table 中没有 product.id 查询时不执行。我试图用 IF 和 IF NULL 做一些事情,但没有成功。

我想看看它是否是空的 images.src 将它们覆盖为 'empty.jpg' OR 1

4

1 回答 1

0

尝试使用内部联接

SELECT product.user_id, product.type, product.body, product.created, product.id, product.url, product.name, product.price, images.src 
FROM xn_product AS product 
INNER JOIN xn_images AS images ON product.id = images.item_id 
WHERE product.active = '1' AND images.type = 'product' AND product.promoted = '1' AND images.main = '1' AND product.url = '". $url ."'
于 2013-10-11T11:26:26.663 回答