====== Mysql ======
A tester en alternative de phpmyadmin => http://www.chive-project.com/
===== Tuto =====
* http://www.mysqltutorial.org/
===== Cas d'une table de config avec une date =====
^ id ^ user_id ^ date ^ name ^
| 1 | 1 | 2020-03-10 | toto |
| 2 | 1 | 2020-03-20 | super toto |
| 3 | 2 | 2020-01-01 | tata |
je veux les derniers nom des utilisateurs
select user_id, name
from users t1
WHERE EXISTS(SELECT 1
FROM users t2
WHERE t2.user_id = t1.user_id
GROUP BY t2.user_id
HAVING t1.date= MAX(t2.date))
^ user_id ^ name ^
| 1 | super toto |
| 2 | tata |
Par contre, si vous avez des date dans le futur, il faudra utiliser cette requête
select user_id, name
from users t1
WHERE EXISTS(SELECT 1
FROM users t2
WHERE t2.user_id = t1.user_id and t2.date<=now()
GROUP BY t2.user_id
HAVING t1.date= MAX(t2.date))
Variantes de la 1ère requête qui semble plus rapide
select t1.user_id,t1.name
from users as t1,
(
select user_id, MAX(date) as date
from users
group by user_id
) as t2
where
t1.user_id=t2.user_id and t1.date=t2.date