Given a TABLE, in this TABLE, it prints entry of the table. If table is empty then it gives NULL.
Examples:
QUESTION : Given an employee table, print name from the given table which id equals to 2.
Output : Geek2QUESTION : Given same Employee table, print name from the given table which id equals to 5.
Output : NULL
Approach: In this case, we use here IFNULL. IFNULL print the null if the table is an empty or other condition.
Query:-
SELECT IFNULL( (SELECT NAME from employee where id = 2), 'NULL') as NAME;
Output:- Geek2
Query:-
SELECT IFNULL( (SELECT NAME from employee where id = 5), 'NULL') as NAME;
Output:- NULL
Recommended Posts:
- MySQL | Common MySQL Queries
- MySQL | LEAD() and LAG() Function
- PHP | MySQL UPDATE Query
- PHP | MySQL Database Introduction
- PHP | MySQL ( Creating Database )
- PHP | MySQL ( Creating Table )
- PHP | Inserting into MySQL database
- PHP | MySQL Select Query
- PHP | MySQL Delete Query
- PHP | MySQL ORDER BY Clause
- PHP | MySQL WHERE Clause
- MySQL | CREATE USER Statement
- MySQL | Change User Password
- PHP | MySQL LIMIT Clause
- MySQL | DROP USER
- MySQL | RENAME USER
- MySQL | DATABASE() and CURRENT_USER() Functions
- MySQL | BIN() Function
- MySQL | LAST_DAY() Function
- MySQL | Grant / Revoke Privileges
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


