Good day,
I have a MySQL table descriptions, which holds fields such as: lang_id, label, short_description, long_description and is_default.
In my application, product descriptions are fetched from the database according to the current language. Everything works fine for now, however I'd like to add a default descriptions for each product so that whevener a description in the desired language isn't found, the default description will be fetched instead.
Right now, my requests look like this:
SELECT
description.id AS record_id
description.label,
description.short_description,
description.long_description
FROM
products,
description,
languages
WHERE
products.id = '.$someProductID.' AND
products.id = description.product_id AND
languages.id = description.lang_id AND
languages.code = "'.$someLang.'"
Does anyone have a solution for fetching the default description of a product when the desired translation doesn't exist ?
I thought of adding some IFNULL statements to my request, something like this:
IFNULL(description.label, (SELECT label FROM description WHERE product_id = '.$someProductID.' AND is_default = 1) ) AS label
But I'm not very familiar with such complex queries and I couldn't make it work.
I'm open to suggestions ;)
Thank you !