我有 2 张表要注册。第一个是注册有id_registration
和entry_date
。第二个是历史,有id_history
、id_registration
和entry_date
TABLE REGISTRATION
id_registration | entry_date
----------------------------
1 | 2021-02-07
2 | 2021-02-08
----------------------------
TABLE HISTORY
id_history | id_registration | entry_date
-----------------------------------------
1 | 1 | 2021-02-07
2 | 2 | 2021-02-08
3 | 1 | 2021-02-08
-----------------------------------------
在历史表中,有两行具有相同的 id_registration。所以,我想从 entry_date
获取最新的引用。这是我的查询
SELECT r.id_registration
, h.id_history
, h.entry_date
FROM registration AS r
LEFT
JOIN history AS h
ON h.id_registration = r.id_registration
GROUP
BY h.id_registration
ORDER BY h.entry_date DESC
但是这个查询的结果是:
id_registration | id_history | entry_date
-----------------------------------------
2 | 2 | 2021-02-08
1 | 1 | 2021-02-07
-----------------------------------------
我期望的是:
id_registration | id_history | entry_date
-----------------------------------------
1 | 3 | 2021-02-08
2 | 2 | 2021-02-08
-----------------------------------------
我的查询有什么错误?