I have a table with languages.
I would like to make a query that gets rows with specified language, but if it won't return any data - with default language.
Is this possible to do in one query?
UPDATE:
My table: Language Fields:
id - (primary key, unique),
lang - (text, not unique),
content - (text, not unique).
and my current query is:
SELECT * FROM Languages WHERE (id='1') AND (lang = 'es')
As I mentioned before if above query won't return anything I would like to get results form default language:
SELECT * FROM Languages WHERE (id='1') AND (lang = 'en')
'en' is default language in this example.
Something like this:
(SELECT CASE
WHEN ((SELECT ID FROM table WHERE language = specified language) IS NULL)
THEN
default language
ELSE
specified language
END);
It will return your desired language, based on the result of the subquery. Plug that into the WHERE clause of your final query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With