Hi Kristina, > //====== > SELECT i.id, i.name, i.whatever, > COALESCE(i.specific1, d.default1) as val1, > COALESCE(i.specific2, d.default2) as val2 > FROM tblInstance i > LEFT OUTER JOIN tblDefault d > ON i.foreignKey = d.primaryKey; > > COALESCE selects the first non-null value of its arguments, and the > left outer join makes sure all records from the left table are > returned. > //==== > > Here is a nifty example of the COALESCE function that I found. So > basically this function is used to handle possible NULL values in a > join ... or...?
That is a good example - an elegant if/else if/else :) > Is this a MySQL specific thing or do other DBs use this function? More or less. Databases will have wonderfully standardized ways of interpreting NULL, and even the functionality of this function, but the concept is always the same. This of course effectively rendering database abstraction layers in PHP meaningless :) H _______________________________________________ New York PHP Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk NYPHPCon 2006 Presentations Online http://www.nyphpcon.com Show Your Participation in New York PHP http://www.nyphp.org/show_participation.php
