I have table1 with the following records:
campo1 campo2 campo3
Adrian 25 2016-09-17
Juan 27 2016-09-14
Alex 23 2016-09-03
Ana 31 2016-09-17
Rocio 29 2016-09-17
In the supposed case that field3 is always being modified but not all the records at the same time, as I can get only the records that have the most recent date, try to do it with max()
Select * from tabla1 where campo3 = max(campo3);
In this case I want to get the following result:
campo1 campo2 campo3
Adrian 25 2016-09-17
Ana 31 2016-09-17
Rocio 29 2016-09-17
but I repeat that date again, it will not be fixed, it will always be modified, so try to obtain the most recent date with max(), I already tried to group and nothing, if you are so kind to explain to me what I am failing or what would be the logic that applies
The query would look like this:
If you have several with the same
id
and you only want to get the largest:Given the table:
CREATE TABLE
repetidosTimestamp
(c1
int(11) NOT NULL DEFAULT '0',c2
varchar(100) DEFAULT NULL,c3
varchar(100) DEFAULT NULL,c4
date DEFAULT NULL, PRIMARY KEY (c1
) ) ENGINE=InnoDB DEFAULT CHARSET=latin1With the following data:
this expression:
Select * from repeatedTimestamp as one WHERE c4 in (SELECT MAX(c4) FROM repeatedTimestamp where one.c2=c2) order by c4 DESC;
will give you this answer:
which are all the new records, cleaning the old records from the table according to the time field.