Conditions

There are conditional commands for MySQL too.

IF/ELSE

SELECT 
    FieldA as A,
    FieldB as B,
    IF(FieldA = FieldB, 'equal', 'not equal') as condition,
FROM
    table
WHERE
    this LIKE that

Or cascaded:

SELECT 
    FieldA as A,
    FieldB as B,
    IF(FieldA = FieldB,'FieldA is equal to FieldB',IF(FieldC = FieldD,'FieldC is equal to FieldD','all false')) as output,
FROM
    table
WHERE
    this LIKE that

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.