Complete the code to select the first non-null value between column1 and 'default'.
SELECT COALESCE(column1, [1]) FROM table1;The COALESCE function returns the first non-null value. Here, if column1 is null, it returns the string 'default'.
Complete the code to replace NULL in salary with 0.
SELECT employee_id, COALESCE(salary, [1]) AS salary FROM employees;Using 0 replaces NULL salaries with zero as a number, which is appropriate for numeric columns.
Fix the error in the code to return the first non-null value between address and 'Unknown'.
SELECT COALESCE([1], 'Unknown') FROM customers;
The column name address should not be in quotes. Quotes make it a string literal, not a column reference.
Fill both blanks to select the first non-null value between phone and email, or 'N/A' if both are null.
SELECT COALESCE([1], [2], 'N/A') FROM contacts;
Use column names phone and email without quotes to check their values. The COALESCE returns the first non-null among them or 'N/A'.
Fill all three blanks to select the first non-null value among city, state, and 'Unknown'.
SELECT COALESCE([1], [2], [3]) FROM locations;
The COALESCE function checks city and state columns first, then returns the string 'Unknown' if both are null.