I need this query:
SELECT * FROM best WHERE best = 'value' AND lang = 'x'
UNION
SELECT * FROM best WHERE best = 'value' AND lang = 'custom'
LIMIT 1
Basically I just need one record where best = 'value' and lang = 'x', if this record isn't found then I need to execute the second query with lang = 'custom'
Is MySQL smart enough to understand that considering there is the LIMIT 1, when the first query of union returns something he doens't need to execute the second query?
To have just one query I could do:
SELECT * FROM best WHERE best = 'value' AND lang IN ('x','custom') LIMIT 1
But with this query I can't say give more priority to record with lang = 'x'