[UPHPU] discovered ISNULL() for default join values in MySQL

Joseph Scott joseph at josephscott.org
Mon Feb 22 18:16:06 MST 2010


On Mon, Feb 22, 2010 at 6:10 PM, Wade Preston Shearer
<wadeshearer.lists at me.com> wrote:
> Sorry; here's an example:
>
> SELECT hans.this, hans.that, ISNULL(frans.the, 'default value') as other
> FROM database_hans hans
> LEFT JOIN database_frans frans
>        ON hans.fk=frans.pk



So wouldn't this be the same:

SELECT hans.this, hans.that, COALESCE(frans.the, 'default value') as other
FROM database_hans hans
LEFT JOIN database_frans frans
       ON hans.fk=frans.pk


Since COALESCE will return the first non-null item in the list given
to it.  If frans.the is not null then it will be used, and if it is
null then you'll get back 'default value' since that string will never
be null.

-- 
Joseph Scott
joseph at josephscott.org
http://josephscott.org/


More information about the UPHPU mailing list