我有以下2个表格:
这是我目前的查询:
SELECT `prod_combined`.`sku`, `prod_combined`.`titel`, `prod_combined`.`preis_vk`, `prod_performance`.*
FROM `prod_combined`
INNER JOIN `prod_performance` ON prod_combined.sku = prod_performance.sku AND
prod_performance.partner_id = 801
WHERE (aktiv = 1) AND (active >= 0)
AND prod_combined.sku = 1006224000
LIMIT 5
在此版本中,必须将字段“active”设置为大于0的值。
但我需要一个查询,将JOIN视为非强制性。例如。如果从prod_combined到prod_performance的连接对于此产品不成功,它也将被查询提取。
我是否已经充分解释了这一点?
此致
最高
答案 0 :(得分:1)
这应该对你有用:
SELECT `prod_combined`.`sku`, `prod_combined`.`titel`, `prod_combined`.`preis_vk`, `prod_performance`.*
FROM `prod_combined`
LEFT JOIN `prod_performance` ON prod_combined.sku = prod_performance.sku
AND prod_performance.partner_id = 801
AND prod_performance.active >= 0
WHERE prod_combined.aktiv = 1
AND prod_combined.sku = 1006224000
LIMIT 5
LEFT JOIN
将确保如果要从prod_performance
添加信息,则会显示
答案 1 :(得分:1)
SELECT
a.sku,
a.titel,
a.preis_vk,
b.*
FROM
prod_combined a
LEFT JOIN
prod_performance b ON a.sku = b.sku
AND b.partner_id = 801
AND b.active >= 0
WHERE
a.aktiv = 1 AND a.sku = 1006224000
LIMIT 5