Top "Greatest-n-per-group" questions

Query the row with the greatest/least value per group.

How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?

My table is: id home datetime player resource ---|-----|------------|--------|--------- 1 | 10 | 04/03/2009 | john | 399 2 | 11 | 04/03/2009 | juliet | 244 5 | 12 | 04/03/2009 | borat | 555 3 | 10 | 03/03/2009 | john | 300 4 | 11 | 03/03/2009 | juliet | 200 6 | 12 | 03/03/2009 | borat | 500 7 | 13 | 24/12/2008 | borat | 600 8 | 13 | 01/01/2009 | …

mysql sql max distinct greatest-n-per-group
SQL select only rows with max value on a column

I have this table for documents (simplified version here): +------+-------+--------------------------------------+ | id | rev | content | +------+-------+--------------------------------------+ | 1 | 1 | ... | | 2 | 1 | ... | | 1 | 2 | ... | | 1 | 3 | ... | +------+-------+…

mysql sql aggregate-functions greatest-n-per-group groupwise-maximum
Select first row in each GROUP BY group?

As the title suggests, I'd like to select the first row of each set of rows grouped with a GROUP …

sql sqlite postgresql group-by greatest-n-per-group
how do I query sql for a latest record date for each user

I have a table that is a collection entries as to when a user was logged on. username, date, value …

sql greatest-n-per-group
Retrieving the last record in each group - MySQL

There is a table messages that contains data as shown below: Id Name Other_Columns ------------------------- 1 A A_data_1 2 A …

sql mysql group-by greatest-n-per-group
How do I do top 1 in Oracle?

How do I do the following? select top 1 Fname from MyTbl In Oracle 11g?

sql oracle oracle11g greatest-n-per-group
Get top 1 row of each group

I have a table which I want to get the latest entry for each group. Here's the table: DocumentStatusLogs Table |…

sql tsql sql-server-2005 group-by greatest-n-per-group
Fetch the row which has the Max value for a column

Table: UserId, Value, Date. I want to get the UserId, Value for the max(Date) for each UserId. That is, …

sql oracle greatest-n-per-group
ROW_NUMBER() in MySQL

Is there a nice way in MySQL to replicate the SQL Server function ROW_NUMBER()? For example: SELECT col1, col2, …

mysql sql greatest-n-per-group rank row-number
Select top 10 records for each category

I want to return top 10 records from each section in one query. Can anyone help with how to do it? …

sql sql-server sql-server-2005 greatest-n-per-group