I have this query, but I want to only join PostageRules and PostageGroups if p.delivery has a value of -1
To clarify, I only want one delivery value, if p.delivery is -1 then we need to get the po.delivery value from the PostageRules table. At the moment the query gets the po.delivery regardless of the value of p.delivery
Is this possible to achieve in a single query?
SELECT
p.id as prod_id, p.delivery as delivery,
po.delivery AS delivery
FROM
products AS p
LEFT JOIN
PostageRules AS po ON p.shopkeeper = po.shopkeeper
LEFT JOIN
PostageGroups AS pg ON po.groupID = pg.id
AND po.minQty <= 1
AND po.maxQty >= 1
AND po.minPrice <= p.Price
AND po.maxPrice >= p.Price
AND po.minWeight <= p.weight
AND po.maxWeight >= p.weight
WHERE
(p.id = '32323')
ORDER BY
po.preference
1 Answer