mysql - Why wont coalesce or is null work on results from a left join? -


in following sql, why wont coalesce work, or null? have because of left join in there?

there no rows subquery return in case. i. e itemid = 'us1' not exist in table amgb.

i'm on mysql 5.5.25 on windows 7 64.

select  a.itemname,   (select coalesce(itemimagename,'default.jpg') // null     amgb b     a.userid = b.userid , a.itemid = b.itemid     limit 1   ) itemimagename amga  a.userid = 1 , a.itemid = 'us1';  (select if(itemimagename null,'default.jpg',itemimagename) // null 

the reason it's null because coalesce inside of subquery. instead move outside this:

select  a.itemname,   coalesce((select itemimagename      amgb b     a.userid = b.userid , a.itemid = b.itemid     limit 1   ), 'default.jpg') itemimagename amga  a.userid = 1 , a.itemid = 'us1'; 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -