Given a TABLE, in this TABLE, it prints entry of the table. If table is empty then it gives NULL.
QUESTION : Given an employee table, print name from the given table which id equals to 2.
Output : Geek2
QUESTION : 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.
SELECT IFNULL( (SELECT NAME from employee where id = 2), 'NULL') as NAME;
SELECT IFNULL( (SELECT NAME from employee where id = 5), 'NULL') as NAME;
- PHP | MySQL WHERE Clause
- How to get ID of the last updated row in MySQL?
- MySQL | BIN() Function
- MongoDB vs MySQL
- MySQL | Hexadecimal Literals
- Difference between MySQL and MS SQL Server
- MySQL | Operator precedence
- MySQL | LAST_DAY() Function
- Mathematical functions in MySQL
- Different types of Procedures in MySQL
- MySQL | DEFAULT() Function
- MySQL | PARTITION BY Clause
- MySQL | Group_CONCAT() Function
- MySQL | Ranking Functions
- PHP | MySQL ( Creating Table )
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.