Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql select latest entry by time

I have the following table:

ID NAME TIME
1  A    0
2  A    3
3  B    1
I am using the query below which produces:

SELECT * FROM `table` GROUP BY `NAME`
ID NAME TIME
1  A    0
3  B    1
And I want use GROUP BY to generate a result like this (discount sort by the TIME column):

ID NAME TIME
2  A    3
3  B    1





SELECT NAME, MAX(TIME) as TIME 
FROM table 
GROUP BY time 
ORDER BY time DESC
Comment

PREVIOUS NEXT
Code Example
Sql :: sql online 
Sql :: sql select from multiple tables without join 
Sql :: having count oracle two columns 
Sql :: mysql query where in 
Sql :: oracle group 
Sql :: convert dd/mm/yyyy to yyyy-mm-dd in sql server 
Sql :: json_value oracle 
Sql :: update select mysql 
Sql :: error 1054 mysql 
Sql :: oracle all dates between two dates 
Sql :: mysql create table index 
Sql :: sql server version check 
Sql :: postgresql backup and restore globals and data 
Sql :: oracle show errors 
Sql :: from . import _mysql ImportError: libmariadb.so.3: cannot open shared object file: No such file or directory linux 
Sql :: show function mysql 
Sql :: oracle privileges users 
Sql :: mysql remove database 
Sql :: oracle sql unique 
Sql :: mysql:5.6 syntax create table 
Sql :: postgresql select case insensitive 
Sql :: order by number of character in sql 
Sql :: how to find max and min salary in sql 
Sql :: change database postgres 
Sql :: declare date variable sql 
Sql :: add column mysql with foreign key 
Sql :: ERROR: permission denied for table accounts postgresql 13 
Sql :: how to find first 3 highest salary in sql 
Sql :: ORACLE CALL BACK TRACE 
Sql :: sql select rows with simlar names 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =