4
我有2個表,例如讓我們假設這是數據:最近用戶查詢
用戶表:
------------------------------
| user_id | username |
------------------------------
| 1 | danny |
| 2 | george |
| 3 | lana |
| 4 | kim |
| 5 | tim |
------------------------------
users_logins表:
-----------------------------------------------
| record_id | user_id | recorder |
-----------------------------------------------
| 1 | 3 | 2012-11-06 04:18:26 |
| 2 | 3 | 2012-11-06 04:31:05 |
| 3 | 2 | 2012-11-06 03:44:22 |
| 4 | 1 | 2012-11-06 04:18:58 |
| 5 | 1 | 2012-11-06 04:30:15 |
| 6 | 3 | 2012-11-06 04:31:05 | X
| 7 | 1 | 2012-11-06 05:53:47 |
| 8 | 1 | 2012-11-06 05:55:15 | X
| 9 | 4 | 2012-11-06 05:59:31 |
| 10 | 4 | 2012-11-06 06:12:55 | X
-----------------------------------------------
我想說明3最近登錄的用戶,所以結果將只顯示標有X的行,或者用最近登錄的唯一字顯示。
查詢將如何?