Linked Questions
693 questions linked to/from SQL select only rows with max value on a column
1359 votes
34 answers
1.3m views
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 A_data_2 3 A A_data_3 4 B ...
76 votes
6 answers
163k views
How to get the latest record in each group using GROUP BY? [duplicate]
Let's say I have a table called messages with the columns: id | from_id | to_id | subject | message | timestamp I want to get the latest message from each user only, like you would see in your ...
41 votes
6 answers
228k views
select rows in sql with latest date for each ID repeated multiple times [duplicate]
I have a table where each ID is repeated 3 times. there is a date in front of each id in each row. I want to select entire row for each ID where date is latest. There are total 370 columns in this ...
7 votes
4 answers
16k views
SQL select max of a group [duplicate]
The initial table is like this: Fruit | Item_ID | Production_line | Amount_produced | Production_date --------------------------------------------------------------- Apples | 652 | 1 ...
2 votes
4 answers
32k views
SQL to get max value from each group [duplicate]
Say I have a table Table Plays date | track_id | user_id | rating ----------------------------------------- 20170416 | 1 | 1 | 3 (***) 20170417 | 1 | 1 | 5 20170418 ...
0 votes
2 answers
19k views
MySQL group and select only first from each group [duplicate]
I would like to perform a query that will select only the most recent item from a given group. In this example, I'm tracking vans: Each time they return to base, a check-in is recorded with ...
3 votes
5 answers
9k views
How to Select row with maximum date [duplicate]
this is my table name tblPE PEID |idnum | PE_DATE_EXAM | ATTENDANCE 1 | 39 | 2014-08-01 | PRESENT 2 | 42 | 2014-08-10 | ABSENT 3 | 39 | 2014-08-...
2 votes
1 answer
12k views
Select user id with a minimum value SQL [duplicate]
How do I select from a database table a user id that is linked to the minimum value of the table for example User ID Pending ------- -------- 0 5 1 4 2 7 '$...
1 vote
4 answers
10k views
Select max date and max time from query [duplicate]
This is my current data in database. ======================================== id | IC |date |time | 1 | test |2017-07-27 |14:19:26 | 2 | test |2017-07-...
3 votes
3 answers
1k views
SELECT .. FROM (SELECT .. FROM ..). How can I improve this query? [duplicate]
I'm learning SQL and have been going through the chapters of the GalaXQL app. I've written the following query in answer to the question "Hilight the star (or stars) which has the planet with the ...
1 vote
2 answers
5k views
LIMIT one row per ID (MySQL) [duplicate]
I have joined a few tables in a MySQL query and they are linked by employee id number. The ID number is unique in tables A and B but have multiple rows in table C with a date (stored as a string) ...
0 votes
1 answer
5k views
Finding the MAX value for each day in a month over multiple years in MySQL [duplicate]
I've got a database full of weather data...specifically the date, max temp, min temp, and daily rainfall for more than 100 years. I'm trying to find the maximum temperature for each day and the ...
0 votes
3 answers
2k views
MySQL - SELECT all columns WHERE one column is DISTINCT by Last date [duplicate]
I have a table with data like the following: Name, City, LastUpdated. I want to get all the data from table distinct by name but only record where last updated is latest. For e.g. if there are 2 ...
3 votes
2 answers
4k views
Getting First Order Date for Each Customer [duplicate]
this one is driving me to drink so I would love some help. I've got a table with: act_Address, act_OrderID, act_Date I'm trying to get the first act_Date for each address we shipped to. Here's what ...
0 votes
1 answer
4k views
which is not functionally dependent on columns in group by clause this is incompatible with sql_modeonly_full_group [duplicate]
select countrycode,name, max(population) from city group by CountryCode LIMIT 0, 1000 Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column '...