Top "Greatest-n-per-group" questions

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

How to construct a SQLite query to GROUP by ORDER?

I've got a rather interesting situation. I have a SQLite database full of addresses and messages (addresses are not unique; …

android sql sqlite greatest-n-per-group
How do I join the most recent row in one table to another table?

I have data that looks like this: entities id name 1 Apple 2 Orange 3 Banana Periodically, a process will run and give …

sql date join greatest-n-per-group
Oracle SQL query: Retrieve latest values per group based on time

I have the following table in an Oracle DB id date quantity 1 2010-01-04 11:00 152 2 2010-01-04 11:00 210 1 2010-01-04 10:45 132 2 2010-01-04 10:45 318 4 2010…

sql oracle greatest-n-per-group top-n
Select records based on last date

Based on the table called Course below: How can I select records which have course name with latest date? I …

sql database postgresql greatest-n-per-group
SQL SELECT TOP 1 FOR EACH GROUP

I have had a look through the other questions and can't quite find what i'm looking for I have an …

sql sql-server greatest-n-per-group
SQL server select distinct rows using most recent value only

I have a table that has the following columns Id ForeignKeyId AttributeName AttributeValue Created Some of the data may look …

sql sql-server sql-server-2005 tsql greatest-n-per-group
Get records with highest/smallest <whatever> per group

How to do that? Former title of this question was "using rank (@Rank := @Rank + 1) in complex query with subqueries - …

mysql subquery greatest-n-per-group rank
Postgresql extract last row for each id

Suppose I've next data id date another_info 1 2014-02-01 kjkj 1 2014-03-11 ajskj 1 2014-05-13 kgfd 2 2014-02-01 SADA 3 2014…

sql postgresql greatest-n-per-group
Oracle SQL -- Analytic functions OVER a group?

My table: ID NUM VAL 1 1 Hello 1 2 Goodbye 2 2 Hey 2 4 What's up? 3 5 See you If I want to return the max number …

sql oracle greatest-n-per-group
SELECT query return 1 row from each group

This is a product table and have few million of records. I want to list record as below:Normally I …

mysql sql select greatest-n-per-group