Here is a dummy test i made up (oops i forgot id). I’d like to write one query which will return the higest grp # in each group id. Which in this case is the last 2 rows unless i delete the last row. Then it’d be the last row and 2nd row. Anyways i have no idea how to write the query w/o using a subquery and its been a while that i forgot how to write a subquery (thats a good thing right?)
CREATE TABLE example ( gid INT, grp INT, data VARCHAR(100) );
--
mysql> select * from example;
+------+------+------+
| gid | grp | data |
+------+------+------+
| 1 | 1 | a |
| 1 | 2 | a |
| 2 | 1 | a |
| 2 | 2 | a |
| 1 | 5 | a |
+------+------+------+
1 Answer