Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Which is more effifcient?

Author  Topic 

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-11 : 07:13:08
Hi Experts,

I have two queries for a solution are below..
which of them is MORE efficient? and WHY ?

1)

select
count(c.custid) as postcode
from customers c
inner join customeraddress ca
on c.custid=ca.custid and c.companyid=ca.companyid
where (ca.postcode = '' OR postcode is null)


2)

select
count(T.custid) as postcode
FROM
(
select C.custid,
case when (ca.postcode = '' OR ca.postcode is null) THEN 0 ELSE 1 END AS CNT
from customers c
inner join customeraddress ca
on c.custid=ca.custid and c.companyid=ca.companyid
)AS T

WHERE
T.CNT = 0


ok tanx...

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-11-11 : 07:18:02
check the execution plan
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-11 : 07:26:46
one more info.
both table has near 1 lakh records

any suggestions ?
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2008-11-11 : 07:46:32
Inner join is always fast as compared sub-query
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-11 : 07:50:28
hi
but both query have inner joins on same tables.
the difference is in their condtions.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-11 : 23:37:47
one of factors that determine the query speed is what all indexes you've on table
Go to Top of Page
   

- Advertisement -