Q1
True / FalseThe MySQL COALESCE function returns the first non-NULL value in the list of expressions.
The COALESCE function evaluates the expressions in the order they are given and returns the first non-NULL value.
Q2
True / FalseIn MySQL, COALESCE(NULL, 'default') will return NULL.
COALESCE(NULL, 'default') will return 'default' because it is the first non-NULL value.
Q3
True / FalseThe MySQL COALESCE function can only take two arguments.
The COALESCE function can take multiple arguments.
Q4
True / FalseThe MySQL COALESCE function can be used to handle NULL values in a SELECT statement.
COALESCE is commonly used in SELECT statements to replace NULL values with a specified value.
Q5
True / FalseIn MySQL, COALESCE and IFNULL are completely interchangeable.
While COALESCE and IFNULL can often be used for similar purposes, COALESCE can take multiple arguments, whereas IFNULL can only take two.
Q6
True / FalseUsing the COALESCE function in MySQL can improve query performance compared to using multiple IF statements.
COALESCE is often more efficient and readable than using multiple IF statements to handle NULL values.
Q7
True / FalseIn MySQL, COALESCE can be used within an UPDATE statement to set a column value based on multiple conditions.
COALESCE can be used in an UPDATE statement to set a column's value based on the first non-NULL condition.
Q8
True / FalseThe MySQL COALESCE function evaluates all its arguments, even if the first one is non-NULL.
COALESCE stops evaluating once it finds the first non-NULL value, it does not evaluate the remaining arguments.
Q9
True / FalseIn MySQL, COALESCE(NULL, NULL, NULL) will return an error.
COALESCE(NULL, NULL, NULL) will return NULL, as all arguments are NULL.
Q10
True / FalseIn a MySQL certification exam, you might encounter a question asking whether the COALESCE function can handle expressions of different data types.
The COALESCE function can handle expressions of different data types, but they must be compatible. The result will be of the type of the first non-NULL expression, according to MySQL's type conversion rules.
Q21
Multiple ChoiceWhich SQL query uses COALESCE to replace NULL values in the 'phone' column with the value 'N/A'?
SQL Code
SELECT employee_id, COALESCE(phone, 'N/A') AS phone_number
FROM employees;
The COALESCE function checks the 'phone' column and returns 'N/A' if it contains a NULL value, otherwise it returns the actual phone number.
Q22
Multiple ChoiceIdentify the SQL query that uses COALESCE to handle NULL values in multiple columns for an employee's contact information.
SQL Code
SELECT employee_id, COALESCE(phone, email, 'No Contact') AS contact_info
FROM employees;
The COALESCE function evaluates each column in order and returns the first non-NULL value it encounters. If all values are NULL, it returns 'No Contact'.
Q23
Multiple ChoiceWhich SQL query uses COALESCE to display the first available price for products across different price columns?
SQL Code
SELECT product_name, COALESCE(price_2022, price_2021, price_2020) AS current_price
FROM products;
The COALESCE function returns the first non-NULL price from the available columns, ensuring that the most recent price is displayed if available.
Q24
Multiple ChoiceDetermine the SQL query that uses COALESCE to replace NULL values in an 'address' column with values from other address-related columns.
SQL Code
SELECT customer_id, COALESCE(address, alternate_address, 'Address Not Available') AS full_address
FROM customers;
The COALESCE function checks each address-related column in order, returning the first non-NULL value or 'Address Not Available' if all are NULL.
Q25
Multiple ChoiceWhich SQL query uses COALESCE to fill missing 'department' values with 'Unknown' and then with 'General' if both are NULL?
SQL Code
SELECT employee_id, COALESCE(department, 'Unknown', 'General') AS department_name
FROM employees;
The COALESCE function checks for NULL in the 'department' column and replaces it first with 'Unknown' and then 'General' if the previous options are also NULL.
Q26
Multiple ChoiceWhich SQL query uses COALESCE to prioritize and display a customer's preferred contact method?
SQL Code
SELECT customer_id, COALESCE(phone, email, 'No Contact Available') AS preferred_contact
FROM customers;
The COALESCE function returns the first non-NULL value between phone and email, providing a fallback to 'No Contact Available' if both are NULL.
Q27
Multiple ChoiceIdentify the SQL query that uses COALESCE to provide a fallback value for missing 'date_of_birth' data.
SQL Code
SELECT employee_id, COALESCE(date_of_birth, '1900-01-01') AS birth_date
FROM employees;
The COALESCE function checks if 'date_of_birth' is NULL and replaces it with '1900-01-01' as a default value.
Q28
Multiple ChoiceWhich SQL query uses COALESCE to combine and display the most recent non-NULL value from multiple review columns?
SQL Code
SELECT product_name, COALESCE(review_2023, review_2022, review_2021, 'No Review') AS latest_review
FROM products;
The COALESCE function checks each review column in order, returning the first non-NULL value or 'No Review' if all are NULL.
Q29
Multiple ChoiceDetermine the SQL query that uses COALESCE to select the first available non-NULL value for a customer's loyalty tier.
SQL Code
SELECT customer_id, COALESCE(loyalty_tier_2023, loyalty_tier_2022, 'Standard') AS current_tier
FROM customers;
The COALESCE function returns the first non-NULL loyalty tier from the available columns, defaulting to 'Standard' if all are NULL.
Q30
Multiple ChoiceWhich SQL query uses COALESCE to handle missing 'discount' values by replacing them with a default of 0?
SQL Code
SELECT order_id, COALESCE(discount, 0) AS applied_discount
FROM orders;
The COALESCE function replaces any NULL 'discount' values with 0, ensuring that all orders have an applied discount value.