Conditionally checking columns
Select students with
gmail
account. Using
IF
statement:
SELECT * 
FROM `students` 
WHERE IF(LENGTH(mail), mail, mail2) LIKE '%gmail.com%'
ORDER BY points
Using
OR
logical operator:
SELECT *
FROM  `students` 
WHERE 
    (`mail` LIKE '%gmail.com%' AND LENGTH(mail))
    OR 
    (mail2 LIKE '%gmail.com%') 
ORDER BY points
Using
CASE
SELECT * 
FROM `students` 
WHERE 
    (CASE
        WHEN LENGTH(mail) THEN mail
        ELSE mail2
    END) LIKE '%gmail.com%'
ORDER BY points
by Valeri Tandilashvili
4 years ago
MySQL
IF
CASE
1
Pro tip: use ```triple backticks around text``` to write in code fences