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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select query

Author  Topic 

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-02-22 : 18:17:01
Hi All,

Here is my code
[code]
select resourceid into #temp
from resource where resourceid<=5

select resource.resourceid
from resource
Left join #temp on #temp.resourceid=resource.resourceid
where #temp.resourceid is null

drop table #temp
[/Code]

Is there any better way to do same this?

Thanks

mk_garg

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-02-22 : 18:28:39
Why can't you just do this:

select resourceid
from resource
where resourceid > 5



Tara
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-02-22 : 18:38:07
You are right tara.
I just modified my requirement so that i makes easy for you.

Basically after some manipulation, i will be getting some resource ids in temp table.

In next query i want to ignore those ids.

I can rewrite it as
[Code]
select resourceid
from resource where resourceid not in
(select resurceid from #temp)
[/Code]

I dont want to use IN operator.

Thanks

mk_garg
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-02-22 : 18:42:44
If you don't want to use IN, then LEFT OUTER JOIN is the way to go. But instead of just saying I don't want to use IN, I would test the performance difference between the two.

select resourceid
from resource where resourceid not in (select resurceid from #temp)

select resource.resourceid
from resource
Left join #temp on #temp.resourceid=resource.resourceid
where #temp.resourceid is null

Tara
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-02-22 : 19:02:35
Hi Tara,

I checked it.
Left Join is faster than IN operator.

Thanks


mk_garg
Go to Top of Page
   

- Advertisement -