Abstract:
I have a SELECT query with a WHERE condition which I would like to have met. In some cases this WHERE condition will not be met and in such cases I would like to use a different WHERE condition. That is the abstract problem I'm facing. Here is a more specific example:
Example:
I have a tag table and a tag_l11n table. The tag table contains basic information about a tag and the tag_l11n table contains the localized name of the tag. In the following simplified SELECT I'm requesting the tag with an English name (tag_l11n_language = 'en')
Query:
SELECT
`tag_3`.`tag_id` as tag_id_3,
`tag_l11n_2`.`tag_l11n_title` as tag_l11n_title_2
FROM
`tag` as tag_3
LEFT JOIN
`tag_l11n` as tag_l11n_2 ON `tag_3`.`tag_id` = `tag_l11n_2`.`tag_l11n_tag`
WHERE
`tag_l11n_2`.`tag_l11n_language` = 'en'
ORDER BY
`tag_3`.`tag_id` ASC
LIMIT 25;
Problem:
The problem starts if a tag doesn't have a certain translation. For example a tag may exist in English language but not in e.g. Italian language. However, the Italian guy would also accept the tags in English language (or any other language) IFF (if and only if) the Italian translation doesn't exist.
In the end I would prefer a solution where I could specify different priorities (1. localization of the user, 2. English, 3. any other language).
I'm a little bit at a loss here. While I could easily omit the condition (language = ??) and filter the result during the output/presentation, I don't think this is the way to go.
tag_l11n_2`.`tag_l11n_language` = 'en'return no rows, then do another - almost the same query but with conditiontag_l11n_2.tag_l11n_language<> 'en'``, is that correct ?