2
我有以下的數據庫表稱爲messages
與列:單柱獲得了唯一的行,其中重複存在
thread_id, sender_id, receiver_id, date
例子:
+-----------+------------+-------------+-------------+
| thread_id | sender_id | receiver_id | date |
+----------------------+-----------+-----------------+
| 1 | 1 | 2 | 11/06/2015 |
| 1 | 2 | 1 | 14/06/2015 |
| 1 | 1 | 2 | 14/06/2015 |
| 1 | 2 | 1 | 20/06/2015 |
| 2 | 1 | 3 | 12/06/2015 |
| 3 | 4 | 2 | 19/06/2015 |
| 3 | 2 | 2 | 20/06/2015 |
+-----------+------------+-------------+-------------+
我需要一個查詢,將最早選擇唯一thread_id
日期和thread_id
不止一次存在。
所以我期望的結果將是:
+-----------+--------------+
| thread_id | date |
+-----------|--------------+
| 1 | 11/06/2015 |
| 3 | 19/06/2015 |
+-----------+--------------+
你缺少一個'組by'何況這是OP希望不是 – ughai
這很接近,比我的解決方案簡單得多。 –