# Ordering a GROUP BY in mySQL

**URL:** <https://forum.kirupa.com/t/ordering-a-group-by-in-mysql/245883>\
**Category:** programming\
**Created:** [December 5, 2007, 6:38am UTC](https://forum.kirupa.com/t/ordering-a-group-by-in-mysql/245883 "2007-12-05T06:38:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![azdak](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@azdak](https://forum.kirupa.com/u/azdak)\
**Post date:** [December 5, 2007, 6:38am UTC](https://forum.kirupa.com/t/ordering-a-group-by-in-mysql/245883/1 "2007-12-05T06:38:33Z")

</div>

OK, as is typical, I’ve started off an experimental project and bitten off WAY more than I can chew. (this is my first try at SQL). The problem-  
I’ve got two tables, urls and comments:

\*\*tbl urls \*\*| id\_urls PRI | url\_urls | date\_urls | kills\_urls  
\*\*tbl comments \*\*| id\_comments PRI | text\_comments | date\_comments | votes\_comments | id\_urls\_comments

I’ve used this:

```auto

SELECT url_urls, kills_urls, date_urls, text_comments, MAX(votes_comments) 
FROM 
(urls LEFT JOIN comments ON urls.id_urls=comments.id_urls_comments) 
GROUP BY url_urls 
ORDER BY kills_urls DESC

```

to return url\_urls, kills\_urls, date\_urls, and text\_comments in order by kils\_url descending. The problem is that GROUP just picks the first match in the joined second table for text\_comments, and I want those ordered by votes\_comments. (the MAX() thing obviously doesn’t work.) I’ve dug around looking for a solution to this for a while, and the only thing I can come up with refers to the “groupwise aggregate” problem. All the solutions are frankly making my head swim, particularly with integrating two tables. Anybody got any ideas?

t
