patternsqlMinor
Getting last row for each day in MySQL
Viewed 0 times
lasteachgettingmysqlforrowday
Problem
I have problem in selecting other columns for the max(datetime) records. In layman terms I need to get relevant columns where max(DialDateTime) records for all the dates in Mysql.
7 rows in set (0.00 sec)
mysql> select max(DialDateTime) as max from log_AP group by date(DialDateTime) ;
+---------------------+
| max |
+---------------------+
| 2012-12-03 07:37:26 |
| 2012-12-04 07:37:04 |
| 2012-12-05 07:37:04 |
| 2012-12-06 07:37:04 |
| 2012-12-07 07:37:04 |
| 2012-12-08 07:37:04 |
| 2012-12-09 07:37:04 |
+---------------------+7 rows in set (0.00 sec)
Solution
You should be able to use a subquery to get the max date and then join that to you table to return the remaining columns:
select a1.*
from log_AP a1
inner join
(
select max(DialDateTime) as max
from log_AP
group by date(DialDateTime)
) a2
on a1.DialDateTime = a2.maxCode Snippets
select a1.*
from log_AP a1
inner join
(
select max(DialDateTime) as max
from log_AP
group by date(DialDateTime)
) a2
on a1.DialDateTime = a2.maxContext
StackExchange Database Administrators Q#30364, answer score: 6
Revisions (0)
No revisions yet.