TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

SQL: Select only rows with Max Value on a Column

6 pointsby adrianonantuaover 11 years ago

2 comments

baxter001over 11 years ago
Or those who happen to be using a dialect of sql with window functions, selecting the rows where:<p>ROW_NUMBER() OVER(PARTITION BY Id ORDER BY Rev DESC) AS &quot;Row Number&quot;<p>Returns 1 is clearer to my mind, with some caveats around dialects which use separate forms of row-number that assign identical&#x2F;differing numbers to two consecutive identical rows.
goldenkeyover 11 years ago
I prefer SELECT table.* FROM table WHERE rev = (SELECT MAX(rev) FROM table WHERE id=table.id)<p>I hate joins. Subselects are so much clearer imo - and you don&#x27;t end up with extra fields.