At 12:09 -0400 10/6/03, Cummings, Shawn (GNAPs) wrote:
For instance;

mysql> select commentid, commentref from comments GROUP BY commentref ORDER by commentref DESC, commentid;
+-----------+------------+
| commentid | commentref |
+-----------+------------+
| 80 | 188 |
| 73 | 187 |
| 76 | 185 |
| 56 | 181 |
| 59 | 180 |
| 60 | 179 |
| 50 | 169 |
...



You can see for record 181 that "56" is the "highest" number after 181 is grouped.

If you include a GROUP BY in your query the way you do without including an aggregate function in the column output list, the query will boil down the output to include one row per commentref value, and choose in an indeterminate fashion what values to display in the other output columns. That's why you're not getting the results you want.

The query using max() suggested by Joseph Bueno looks closer to what you
should be using, as far as I can tell.

However this is not true;

mysql> select commentid, commentref from comments WHERE commentref=181;
+-----------+------------+
| commentid | commentref |
+-----------+------------+
|        56 |        181 |
|        57 |        181 |
|        79 |        181 |
+-----------+------------+

You can see above that id(79)


--
Paul DuBois, Senior Technical Writer
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

Are you MySQL certified? http://www.mysql.com/certification/


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to