Using If else in SQL Select statement

后端 未结 11 1612
感情败类
感情败类 2020-12-24 05:35

I have a select statement which will return 2 columns.

ID | IDParent

Then in my program I have to test if IDParent is < 1 then use

11条回答
  •  隐瞒了意图╮
    2020-12-24 06:07

    Here are two ways "IF" Or "CASE".

    SELECT IF(COLUMN_NAME = "VALUE", "VALUE_1", "VALUE_2") AS COLUMN_NAME 
    FROM TABLE_NAME;
    

    OR

    SELECT (CASE WHEN COLUMN_NAME = "VALUE" THEN 'VALUE_1' ELSE 'VALUE_2' END) AS COLUMN_NAME 
    FROM TABLE_NAME;
    

提交回复
热议问题