SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ROW_NUMBER(): An Efficient Alternative to Subqueries


ROW_NUMBER(): An Efficient Alternative to Subqueries

Author
Message
Brian Barkauskas
Brian Barkauskas
SSC-Enthusiastic
SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)

Group: General Forum Members
Points: 172 Visits: 180

-- how about?
SELECT
pv.ProductID
, pv.Version
, pv.MinorVersion
, pv.ReleaseVersion
, pv.StandardCost
FROM Production.ProductVersion pv WITH (NOLOCK)
WHERE EXISTS (
SELECT *
FROM (
SELECT TOP 1
pv2.ProductID
, pv2.Version
, pv2.MinorVersion
, pv2.ReleaseVersion
FROM Production.ProductVersion pv2 WITH (NOLOCK)
WHERE pv2.ProductID = pv.ProductID
ORDER BY
pv2.ProductID DESC
, pv2.Version DESC
, pv2.MinorVersion DESC
, pv2.ReleaseVersion DESC
) pv2
WHERE pv2.ProductID = pv.ProductID
AND pv2.Version = pv.Version
AND pv2.MinorVersion = pv.MinorVersion
AND pv2.ReleaseVersion = pv.ReleaseVersion
)


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search