從表中獲取最新版本我有一個看起來像這樣的數據庫:通過SQL
ID parent name description _record_status _log_user _log_timestamp _log_type
--------------------------------------------------------------------------------------------------------------------
1 1 This is a rwo! Test content active 1 2012-01-29 15:49:21 create
2 1 This is a row! Test Content active 1 2012-01-29 15:52:14 revision
3 3 Another record! More content active 1 2012-01-29 15:58:43 create
4 4 Deleted Record More content active 1 2012-01-29 15:58:43 create
5 4 Deleted Record More content deleted 1 2012-01-29 15:58:43 destroy
我希望能夠選擇最新的行對於每條記錄,其中記錄不會被刪除。因此,舉例來說,我期望的輸出是:
ID name
------------------
2 This is a row!
3 Another Record!
有沒有辦法通過SQL是有效的,如果沒有,什麼可能我想用PHP做什麼做到這一點做到這一點?
將每個表格的版本分別作爲修訂版本的方式嗎?
您想根據最高ID最新的父母,但如果最高ID被刪除,你不希望這樣的父母呢? – Sparky 2012-02-24 16:09:25
@Sparky正確 – 2012-02-24 16:10:36
對於哪個DBMS是這樣的? – 2012-02-24 16:27:40