Is is faster to filter and get data or filter then get data ?

Posted by remi bourgarel on Stack Overflow See other posts from Stack Overflow or by remi bourgarel
Published on 2010-03-16T13:35:29Z Indexed on 2010/03/16 13:56 UTC
Read the original article Hit count: 200

Filed under:
|
|

Hi

I have this kind of request :

SELECT myTable.ID,
myTable.Adress,
-- 20 more columns of all kind of type
FROM myTable
WHERE EXISTS(SELECT * FROM myLink 
    WHERE myLink.FID = myTable.ID 
    and myLink.FID2 = 666)

myLink has a lot of rows.

Do you think it's faster to do like this :

SELECT myLink.FID INTO @result 
FROM myLink 
WHERE myLink.FID2 = 666

UPDATE @result SET Adress = myTable.Adress,
    -- 20 more columns of all kind of type 
    FROM myTable 
    WHERE myTable.ID = @result.ID

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server