How to get the last data of group by in mysql?

by mallory_cormier , in category: MySQL , a year ago

How to get the last data of group by in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , a year ago

@mallory_cormier 

To get the last data of grouping in MySQL, you can use the MAX() function combined with a subquery. Here's an example:

1
2
3
SELECT your_column1, your_column2, MAX(date_column) AS last_date
FROM your_table
GROUP BY your_column1, your_column2;


Replace your_column1, your_column2, date_column, and your_table with the actual column names and table name from your database.


In this query, the MAX() function is used to retrieve the maximum date from each group. By grouping the data using GROUP BY, you can ensure that the last date for each group is returned.


Remember to adjust the column names and table name according to your specific situation.

Related Threads:

How to get last 1 hour to last 10 days data in mysql?
How to get the top row for each group in a column in mysql?
How to group datetime into intervals of 3 hours in mysql?
How to get data from mysql on python flask?
How to get stored data by delimiter ( ; ) in mysql?
How to get highest count from list data in mysql?