There seems to be no good way, and if possible, you need to do this in the procedure, either by filling out a temporary table or returning a RowSet object to the client
However, if nothing is impossible, it seems that you have a restriction on secondary and tertiary queries:
SELECT * FROM products WHERE language = 1
UNION ALL
SELECT * FROM products WHERE language = 2 AND country = 1
AND NOT EXISTS (SELECT * FROM products WHERE language = 1)
UNION ALL
SELECT * FROM products WHERE language = 2 AND country = 2
AND NOT EXISTS (SELECT * FROM products WHERE language = 1 OR (language = 2 AND country = 1 ))
But it just has to be ugly and slow.
LEFT JOIN with IS NULL may be better than NOT EXISTS, though
source
share