Here’s an interesting SQL function:
Coalesce
Given a list, returns the first non-null value in the list. If all values are null, returns null.
http://www.creativedev.in/2012/03/mysql-coalesce-function/
http://stackoverflow.com/questions/6862373/mysql-join-with-insert-combined