- 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
How does MySQL IF() function work?
MySQL IF() function is one of the MySQL control flow functions that returns a value based on a condition. It is sometimes referred to as IF ELSE or IF THEN ELSE function. Basically, it takes three expressions and if the first expression is true (not ZERO and not NULL), it returns the second expression. Otherwise, it returns the third expression. Its syntax is as follows −
Syntax
IF(expr, value_if_true, value_if_false)
Here
- expr is the expression having some condition.
- Value_if_true is the value to return if expr evaluates to TRUE.
- Value_if_false is the value to return if expr evaluates to FALSE.
Example
mysql> Select IF(100=100,'YES','NO'); +------------------------+ | IF(100=100,'YES','NO') | +------------------------+ | YES | +------------------------+ 1 row in set (0.00 sec) mysql> Select IF(100=200,'YES','NO'); +------------------------+ | IF(100=200,'YES','NO') | +------------------------+ | NO | +------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How does MySQL QUOTE() function work with comparison values?
- How does MySQL CASE work?
- How does recursion function work in JavaScript?
- How does issubclass() function work in Python?
- How does isinstance() function work in Python?
- How does the bin2hex() function work in PHP?
- How does ‘FOR EACH ROW’ work in the MySQL trigger?
- How does comparison operator work with date values in MySQL?
- How does jQuery.scrollTop() work?
- How does jQuery.scrollLeft() work?
- How exactly does work?
- How does RSA work?
- How does classification work?
- How does backpropagation work?
- How does React work?

Advertisements