Identify if at least one row with given condition exists

前端 未结 4 2016
长发绾君心
长发绾君心 2021-02-05 02:59

Employee table has ID and NAME columns. Names can be repeated. I want to find out if there is at least one row with name like \'kaushik%\'.

So query should return true/f

4条回答
  •  花落未央
    2021-02-05 03:42

    How about:

    select max(case when name like 'kraushik%' then 1 else 0 end)
    from employee
    

    Or, what might be more efficient since like can use indexes:

    select count(x)
    from (select 1 as x
          from employee
          where name like 'kraushik%'
         ) t
    where rownum = 1
    

提交回复
热议问题