sql - TOP 1 or EXISTS - Which is faster? -


i have table in database has 2 million records. need find out if more 1 record available customer. have 2 following scripts:

select top 1 ex.exceptionid exception ex ex.customerid='{1bf87745-de00-47ff-9ac0-430baf87679a}' , ex.loanid null , ex.statustype = 'required' , ex.exceptionstate <> 'n'  select (case when exists ( select ex.exceptionid exception ex ex.customerid = '{1bf87745-de00-47ff-9ac0-430baf87679a}' , ex.loanid null , ex.statustype = 'required' , ex.exceptionstate <> 'n') 1 else 0 end) customerexceptioncount 

which 1 faster , why..?

many thanks..!

don't want like,

declare @morethanone bit;  select @morethanone = case when count(*) > 1 1 else 0 end (     select top 2 1     [exception]     [customerid] ='{1bf87745-de00-47ff-9ac0-430baf87679a}'        , [loanid] null        , [statustype] = 'required'        , [exceptionstate] <> 'n' ) [firsttwo] 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -