IF() in MySQL — How It Works

What the MySQL IF() function does, with an example.

Published October 22, 2026

IF() returns one of two values depending on whether a condition is true or false.

Key points

  • Part of standard SQL functions available in MySQL for working with query results

Example

SELECT IF(stock > 0, 'In Stock', 'Out of Stock') FROM products;
More SQL articles