Possible Duplicate:
Retrieving the last record in each group
With the below query I'd get the results one
and three
. How do I get the results for sid
; 15
and 17
? I can't use a WHERE
because I won't know the sid
.
A better way of explaining is, how do I LIMIT
per sid
without grouping?
mysql_query("SELECT *
FROM `mytable`
GROUP BY `sid`
ORDER BY `sid` ASC
LIMIT 0, 2");
+----+-----------+----------+
| id | sid | num |
+----+-----------+----------+
| 1 | 15 | one |
| 2 | 15 | two |
| 3 | 17 | three |
| 4 | 17 | four |
| 5 | 18 | five |
| 6 | 18 | six |