MySQL: How to get the maximum disposition and the maximum date from my database
I've set up the next example:


create table docs(id int, dispo int, dt date, st timestamp);




insert into docs values
(1, 10, '20170406', '2017/04/06 01:30:00'),
(1, 5 , '20170407', '2017/04/07 02:30:00'),
(1, 10, '20170406', '2017/04/06 01:00:00'),
(1, 10, '20170406', '2017/04/06 01:15:00'),
(2,  9, '20170406', '2017/04/06 01:30:00'),
(2,  9, '20170407', '2017/04/07 13:45:00'),
(2,  9, '20170407', '2017/04/07 09:00:00'),
(2,  9, '20170407', '2017/04/07 10:45:00');


First you need to know the MAX disposition of every date:


SELECT   id ID, dt &quot;Date&quot;, max(dispo) Disposition
FROM     docs
GROUP BY id, dt


ID | Date       | Disposition
-: | :--------- | ----------:
 1 | 2017-04-06 |          10
 1 | 2017-04-07 |           5
 2 | 2017-04-06 |           9
 2 | 2017-04-07 |           9


Then you can obtain MAX Stamp by disposition and date.


SELECT   t1.id ID, 
         t1.dispo Disposition, 
         t1.dt &quot;Date&quot;, 
         max(t1.st) Stamp
FROM     docs t1
JOIN     (SELECT   id, dt, max(dispo) as dispo
          FROM     docs
          GROUP BY id, dt) t2
ON        t1.id = t2.id
AND       t1.dispo = t2.dispo
AND       t1.dt = t2.dt
GROUP BY  t1.id, t1.dispo, t1.dt
ORDER BY  t1.id, t1.dt;


ID | Disposition | Date       | Stamp              
-: | ----------: | :--------- | :------------------
 1 |          10 | 2017-04-06 | 2017-04-06 01:30:00
 1 |           5 | 2017-04-07 | 2017-04-07 02:30:00
 2 |           9 | 2017-04-06 | 2017-04-06 01:30:00
 2 |           9 | 2017-04-07 | 2017-04-07 13:45:00


dbfiddle here