Hi Everyone.
I have the following situation:
What i need is the following, and i can't get the right sql command for that.
I need a distinct on the field `order_id` with the maximum value of `memo_id` so i need the output:
Is there anybody who can help me with this?
I have the following situation:
Code:
TABLE: order_memo
mysql> SELECT * FROM
`order_memo` ORDER BY `order_id` LIMIT 10;
+----------+---------+---------------------+-----------+-----------+
| order_id | memo_id | memo_time | status_id | memo_read |
+----------+---------+---------------------+-----------+-----------+
| 1 | 2 | 2005-01-26 02:26:15 | 1 | 2 |
| 1 | 1 | 2005-01-26 02:24:53 | 0 | 2 |
| 1 | 0 | 2005-01-25 11:57:41 | 0 | 1 |
| 2 | 1 | 2005-01-26 02:28:29 | 1 | 2 |
| 2 | 0 | 2005-01-25 18:38:15 | 0 | 1 |
| 3 | 0 | 2005-01-25 18:39:34 | 0 | 1 |
| 3 | 1 | 2005-01-27 04:02:52 | 1 | 2 |
| 4 | 0 | 2005-01-25 18:42:03 | 0 | 1 |
| 4 | 1 | 2005-01-27 04:04:34 | 1 | 2 |
| 5 | 0 | 2005-01-25 18:43:37 | 0 | 1 |
+----------+---------+---------------------+-----------+-----------+
What i need is the following, and i can't get the right sql command for that.
I need a distinct on the field `order_id` with the maximum value of `memo_id` so i need the output:
Code:
+----------+---------+---------------------+-----------+-----------+
| order_id | memo_id | memo_time | status_id | memo_read |
+----------+---------+---------------------+-----------+-----------+
| 1 | 2 | 2005-01-26 02:26:15 | 1 | 2 |
| 2 | 1 | 2005-01-26 02:28:29 | 1 | 2 |
| 3 | 1 | 2005-01-27 04:02:52 | 1 | 2 |
| 4 | 1 | 2005-01-27 04:04:34 | 1 | 2 |
| 5 | 0 | 2005-01-25 18:43:37 | 0 | 1 |
+----------+---------+---------------------+-----------+-----------+
Is there anybody who can help me with this?