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
 SQL Server Development (2000)
 Keys - which is faster

Author  Topic 

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-11-01 : 12:56:09
I'll give an example here. It's kinda rushed, but hopefully you get the idea.

create table X(
RID int,
PID varchar(45),
value varchar(50)
)

Create table y(
RID int,
pida varchar(45),
pidb varchar(25)
)

I want to join tables x and y together to get the value from x for each entry in y. the relationship is one X to many Y.
In table Y PID is 2 values. In table X it's one value... PIDA + PIDB = PID

My question is what would be faster/more effiecent for sql server to run....

select y.rid, x.value
from y inner join x on y.rid = x.rid and
y.PIDA + ' ' + y.PIDB = x.PID

or

Update y set PIDA = y.PIDA + ' ' + y.PIDB
go
select y.rid, x.value
from y inner join x on y.rid = x.rid and
y.PIDA = x.PID


Don't worry about the data and that sort... I'm just wondering if updating the key then joining is more effiecient then just combining the values in the innerjoin

[edit]Bleh, missing comma's in my create tables. How messy[/edit]
-----------------------
SQL isn't just a hobby, It's an addiction

Edited by - m.e. on 11/01/2002 12:58:12
   

- Advertisement -