Group coalesce

OK, I know that coalesce returns the first ‘not null’ value.

I want to bring back the first ‘not null’ value where that value is a series of image_names.

So, what I have written below, is that a hopefully-looking start or plain overly-optimistic?

bazz


COALESCE(ig.business_id, ig2.business_id, ig3.business_id) AS id
     COALESCE( ( ig.sequence_number, i.image_name)
               ( ig2.sequence_number, i2.image_name)
			   ( ig3.sequence_number, i3.image_name) 
			 )

I have tested it and it doesn’t work - erroring on seemingly the second bracket after coalesce. But that’s a syntax issue. Is the notion or structure even close?

COALESCE doesn’t require GROUP BY

whatever you did, we can’t see it

:cool:

blimey, I think I got it. :slight_smile:

removed the nesting from the second COALESCE and added GROUP BY to the bottom as well as an ORDER BY.

Now to check the speed.

bazz

The only other way I can think of is a series of group_concats where the concat is for each of those pairs. But then, I don’t want all of the pairs returned. I want the pair which matches the first coalesce.