if condition in mysql query code example

Example 1: mysql select else if

select id, 
    (
    CASE 
        WHEN qty_1 <= '23' THEN price
        WHEN '23' > qty_1 && qty_2 <= '23' THEN price_2
        WHEN '23' > qty_2 && qty_3 <= '23' THEN price_3
        WHEN '23' > qty_3 THEN price_4
        ELSE 1
    END) AS total
 from product;

Example 2: mysql if statement in where clause

SELECT  `id` ,  `naam` 
FROM  `klanten` 
WHERE IF(`email` != '', `email`, `email2`) LIKE  '%@domain.nl%'

Example 3: in condition in mysql

//Syntax
SELECT * FROM `tableName` WHERE `ColumnName` IN (Value1,Value1,Value1);

//Example:
SELECT * FROM `members` WHERE `membership_number` IN (1,2,3);

Tags:

Sql Example