Possible duplicated MySql Query: Select top 3 rows from table for each category. I'm not clear with that answer that why I asked a again.
This is my database
+-------+----------+-------------+
| id | app_Id | Content |
+-------+----------+-------------+
| 1 | 19 | Hello Peer |
+-------+----------+-------------+
| 2 | 20 | Hello Peer |
+-------+----------+-------------+
| 3 | 19 | Hello Peer |
+-------+----------+-------------+
| 4 | 19 | Hello Peer |
+-------+----------+-------------+
| 5 | 21 | Hello Peer |
+-------+----------+-------------+
| 6 | 20 | Hello Peer |
+-------+----------+-------------+
| 7 | 19 | Hello Peer |
+-------+----------+-------------+
| 8 | 20 | Hello Peer |
+-------+----------+-------------+
| 9 | 21 | Hello Peer |
+-------+----------+-------------+
Now how can I select the record categories by the app_Id and limit 2 for each categories and order by appId desc
If the statement above not clear.Here is my expected output record from the database above.
+-------+----------+-------------+
| id | app_Id | Content |
+-------+----------+-------------+
| 4 | 19 | Hello Peer |
+-------+----------+-------------+
| 7 | 19 | Hello Peer |
+-------+----------+-------------+
| 6 | 20 | Hello Peer |
+-------+----------+-------------+
| 8 | 20 | Hello Peer |
+-------+----------+-------------+
| 5 | 21 | Hello Peer |
+-------+----------+-------------+
| 9 | 21 | Hello Peer |
+-------+----------+-------------+
I want the query to do this any idea?