AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL COALESCE Function |
|
SQL > SQL NULL >
Coalesce Function
The COALESCE function in SQL returns the first non-NULL expression among its arguments. The syntax for COALESCE is as follows: COALESCE scans its list of arguments from left to right and returns the first one that is not NULL — a versatile, ANSI-standard way to substitute fallback values for NULLs.
It is the same as the following CASE statement: For examples, say we have the following table, Table Contact_Info
and we want to find out the best way to contact each person according to the following rules: 1. If a person has a business phone, use the business phone number. 2. If a person does not have a business phone and has a cell phone, use the cell phone number. 3. If a person does not have a business phone, does not have a cell phone, and has a home phone, use the home phone number. We can use the COALESCE function to achieve our goal: Result:
Frequently Asked Questions
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.