說,我有兩個表像這樣:mysql查詢如何才能達到所示結果?
Table group Table user
+----+-----------+ +----+----------+------+----------+
| id | groupname | | id | username | rank | group_id |
+----+-----------+ +----+----------+------+----------+
| 1 | Friends | | 1 | Frank | 1 | 1 |
| 2 | Family | | 2 | Mike | 3 | 1 |
+----+-----------+ | 3 | Steve | 2 | 1 |
| 4 | Tom | 1 | 2 |
+----+----------+------+----------+
而且我想選擇所有組,並得到與各組的最高等級(最高數)的用戶。所以基本上我想得到這個結果:
+-----------------+----------+---------+---------------+
| group.groupname | group.id | user.id | user.username |
+-----------------+----------+---------+---------------+
| Friends | 1 | 2 | Mike |
| Family | 2 | 4 | Tom |
+-----------------+----------+---------+---------------+
選擇如何是像? 它也許很簡單,但我沒有得到它現在....
編輯的結果,使組名被選中,否則對用戶表的簡單查詢會做的伎倆 – acme 2010-01-22 14:51:53