
- 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 to replace 'Empty set' in a MySQL query?
To replace a record that doesn’t exist, use the COALESCE in MySQL. The COALESCE would help in substituting the NULL values. Let us first create a table −
mysql> create table DemoTable -> ( -> Code varchar(20) -> ); Query OK, 0 rows affected (1.64 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('45'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values('78'); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+ | Code | +------+ | 10 | | 45 | | 78 | +------+ 3 rows in set (0.00 sec)
Here is the query to replace 'Empty set' in a MySQL query −
mysql> select COALESCE(MAX(Code), 'false') AS WhenReturnSetIsEmpty -> from DemoTable -> where Code='90';
This will produce the following output −
+----------------------+ | WhenReturnSetIsEmpty | +----------------------+ | false | +----------------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL query to replace null value with empty string in several columns while fetching data
- MySQL query to replace a column value
- How to select an empty result set in MySQL?
- How to set default value for empty row in MySQL?
- MySQL query to update a specific cell to be empty
- MySQL query to convert empty values to NULL?
- How to set all values in a single column MySQL Query?
- Replace the empty values from a MySQL table with a specific value
- MySQL query to display custom text for empty columns
- MySQL query to replace part of string before dot
- MySQL query to replace special characters from column value
- MySQL Query to set currency records
- MySQL query to check if database is empty or not?
- Set the result of a query to a variable in MySQL?
- MySQL query to replace only the backslashes from folder path?

Advertisements