How to set a default row for a query that returns no rows?

后端 未结 11 1465
青春惊慌失措
青春惊慌失措 2020-12-03 06:43

I need to know how to return a default row if no rows exist in a table. What would be the best way to do this? I\'m only returning a single column from this particular table

11条回答
  •  臣服心动
    2020-12-03 06:59

    I figured it out, and it should also work for other systems too. It's a variation of WW's answer.

    select rate 
    from d_payment_index
    where fy = 2007
      and payment_year = 2008
      and program_id = 18
    union
    select 0 as rate 
    from d_payment_index 
    where not exists( select rate 
                      from d_payment_index
                      where fy = 2007
                        and payment_year = 2008
                        and program_id = 18 )
    

提交回复
热议问题