Top "Greatest-n-per-group" questions

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

MySQL Left Join + Min

Seemingly simple MySQL question, but I've never had to do this before.. I have two tables, items and prices, with …

mysql group-by left-join greatest-n-per-group min
SQL: how to limit a join on the first found row?

How to make a join between two tables but limiting to the first row that meets the join condition ? In …

sql oracle join greatest-n-per-group
Nested Select statement in MYSQL join

SELECT * FROM A JOIN B ON B.ID = A.ID AND B.Time = (SELECT max(Time) FROM B B2 WHERE …

mysql join nested greatest-n-per-group
How to select single row based on the max value in multiple rows

Possible Duplicate: SQL: Find the max record per group I have a table with four columns as such: name major …

mysql sql greatest-n-per-group
How to select the first N rows of each group?

I have two SQLite tables like this: AuthorId | AuthorName ---------------------- 1 | Alice 2 | Bob 3 | Carol ... | .... BookId | AuthorId | Title ---------------------------------- 1 | 1 | aaa1 2 | 1 | aaa2 3 | 1 | aaa3 4 | 2 | …

sql sqlite greatest-n-per-group limit-per-group
Retrieving the most recent records within a query

I have the following tables: tblPerson: PersonID | Name --------------------- 1 | John Smith 2 | Jane Doe 3 | David Hoshi tblLocation: LocationID | Timestamp | PersonID | X | …

sql-server sql-server-2005 tsql group-by greatest-n-per-group
COUNT results from SQL Query with a HAVING clause

Are you able to use COUNT in a query with a HAVING clause so that the COUNT returns the number …

sql sql-server count greatest-n-per-group
Selecting the most common value from relation - SQL statement

I have a table within my database that has many records, some records share the same value for one of …

sql mysql greatest-n-per-group
Limit join to one row

I have the following query: SELECT sum((select count(*) as itemCount) * "SalesOrderItems"."price") as amount, 'rma' as "creditType", "Clients"."company" …

sql postgresql join greatest-n-per-group sql-limit
How do I select TOP 5 PERCENT from each group?

I have a sample table like this: CREATE TABLE #TEMP(Category VARCHAR(100), Name VARCHAR(100)) INSERT INTO #TEMP VALUES('A', 'John') …

sql sql-server tsql sql-server-2008 greatest-n-per-group