- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL IF() to display custom YES or NO messages
Let us first create a table −
mysql> create table DemoTable1850 ( OrderStatus varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1850 values('Yes'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1850 values('No'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1850 values('Yes'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1850 values('Yes'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1850;
This will produce the following output −
+-------------+ | OrderStatus | +-------------+ | Yes | | No | | Yes | | Yes | +-------------+ 4 rows in set (0.00 sec)
Here is the query to implement IF() to display custom messages:
mysql> select if(OrderStatus='Yes','Order has been placed','Failed') as Status from DemoTable1850;
This will produce the following output −
+-----------------------+ | Status | +-----------------------+ | Order has been placed | | Failed | | Order has been placed | | Order has been placed | +-----------------------+ 4 rows in set (0.00 sec)
- Related Articles
- Set custom messages for enum values in MySQL
- Write MySQL case statement to set custom messages for student’s result
- Display substring in MySQL if the string is less than a specific length or display a custom message if it is more?
- Set custom messages by working with MySQL IF Statements and SELECT in a user-defined variable
- How to add custom messages to TestNG failure?
- MySQL query to display custom text for empty columns
- How to select sum or 0 if no records exist in MySQL?
- Set custom messages on the basis of a column with student marks in MySQL
- Inline conditions in Lua (a == b ? “yes” : “no”)
- How to write custom Python Exceptions with Error Codes and Error Messages?
- Select count of values (Yes, No) with same ids but different corresponding records in MySQL?
- Using CASE statement in MySQL to display custom name for empty value
- How to display toast messages from a thread in Android?
- How to create a dialog with “yes” and “no” options in JavaScript?
- How to create JavaScript alert with 3 buttons (Yes, No and Cancel)?

Advertisements