
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can I use IFNULL() function at the place of COALESCE() function in MySQL?
As we know that IFNULL() function will return the first argument if it is not NULL otherwise it returns the second argument. On the other hand, COALESCE() function will return first non-NULL argument. Actually, both IFNULL() and COALESCE() functions in MySQL works equivalently if the number of arguments is two only. The reason behind this is that IFNULL() function accepts only two arguments and in contrast, COALESCSE() function can accept any number of arguments.
Suppose if we want to use IFNULL() function at the place of COALESCE() function then the number of arguments must be two. Following example will demonstrate it −
mysql> Select IFNULL(NULL, 'Green'); +-----------------------+ | IFNULL(NULL, 'Green') | +-----------------------+ | Green | +-----------------------+ 1 row in set (0.00 sec) mysql> Select COALESCE(NULL, 'Green'); +-------------------------+ | COALESCE(NULL, 'Green') | +-------------------------+ | Green | +-------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How can I insert a value in a column at the place of NULL using MySQL COALESCE() function?
- What is the use of MySQL IFNULL() control flow function?
- How can MySQL COALESCE() function be used with MySQL SUM() function to customize the output?
- How can I use another MySQL function/s with REPEAT() function?
- How can we apply COALESCE() function on a MySQL table’s data value?
- How can I use MySQL IN() function to compare row constructors?
- How can I use MySQL IF() function within SELECT statement?
- How can I use SPACE() function with MySQL WHERE clause?
- How can I use 2-digit year value in MySQL DATEDIFF() function?
- How can we use MySQL SUM() function?
- How can I use MySQL INTERVAL() function with a column of a table?
- How to convert MySQL null to 0 using COALESCE() function?
- How to use Coalesce in MySQL?
- How can I use TIME_FORMAT() function to offload time/date values in MySQL?
- How can I use a SELECT statement as an argument of MySQL IF() function?

Advertisements