Select a column if other column is null

后端 未结 7 732
庸人自扰
庸人自扰 2020-12-08 13:14

I need to select a field called ProgramID from a table and if the ProgramID is NULL then I need to select the value in the InterimProgramID from the same table and alias it

7条回答
  •  既然无缘
    2020-12-08 13:49

    SELECT ProgramID
      FROM a_table
     WHERE ProgramID IS NOT NULL
    UNION
    SELECT InterimProgramID AS ProgramID
      FROM a_table
     WHERE ProgramID IS NULL;
    

提交回复
热议问题