tags:

views:

44

answers:

1

I'm trying to list all my products' description according to a specified language, and if no translation is found for that language then the default is taken instead.

Please take a look at this paste, everything is explained with the expected results:

http://pastebin.com/m306e670c

I've been working on this for days, so your help is greatly appreciated !

+1  A: 

Note that the lang is defined on the JOIN

   SELECT COALESCE(pd.short_description, t.short_description)
     FROM PRODUCT_DESCRIPTIONS t
LEFT JOIN PRODUCT_DESCRIPTIONS pd ON pd.product_id = t.product_id 
                                 AND pd.lang = 'mk'
    WHERE t.is_default = 1

It won't work if you filter the language in the WHERE clause.

OMG Ponies
+1 assuming there is a *is_default* label for every product id. Otherwise I would start with (FROM) the desired language left-joining on the default (and specifying the t.is_default as another condition of the JOIN rather then in WHERE clause)
van
@van: You can't start with the desired language - you wouldn't get the product_ids where the desired language doesn't exist, so it'd be worthless to try to get the default language short_description value.
OMG Ponies