Hvis tabel product
indeholder mindst én data. Og du vil vise andre kolonner enten NULL
eller tilpasset streng som "---"
du skal i forespørgslen angive den joinforbindelse, selvom joining-attributten er null. Så følgende forespørgsel vil give dig data.
SELECT
p.description AS p_description ,ifnull(pd.description,"---") AS pd_description,
ifnull(psd.description,"--") AS psd_description
FROM product AS p
LEFT JOIN Product_description AS pd ON(pd.product_id = p.product_id)
LEFT JOIN product_store_description AS psd ON(psd.product_id = p.product_id)
WHERE p.product_id = '1' AND (pd.language = 'en' or pd.language is null)
AND (psd.language = 'en' or psd.language is null) AND
(psd.store_id = 1 or psd.store_id is null);