On Wed, Nov 14, 2001 at 09:03:11PM -0800, Christopher Oson wrote:
> Good Day All,
> 
> I have a question....
> 
> mysql> select storyID, storyCategoryID, left(title, 25) title 
>     -> from newsStories where storyCategoryID > 0 
>     -> order by storyCategoryID;
> +---------+-----------------+---------------------------+
> | storyID | storyCategoryID | title                     |
> +---------+-----------------+---------------------------+
> |    4327 |               1 | New Artery Device OK'd    |
> |    4328 |               1 | Pushing 'Low Carcinogen'  |
> |    4383 |               1 | Lasting Relationships     |
> |    4384 |               1 | Anthrax Briefing          |
> |    4385 |               1 | Varicose Veins            |
> |    4513 |               2 | Letters To God            |
> |    4380 |               3 | United We Stand           |
> |    4381 |               3 | Tea Station               |
> |    4382 |               3 | Christmas In July         |
> |    4533 |               7 | test                      |
> +---------+-----------------+---------------------------+
> 
> What I want is a query that will retrieve the MAX(storyID) from *each* 
> storyCategoryID.  I know this is possible with a sub-select and/or a 
> union.  But is this possible without a sub-query or having to run 
> multiple queries?
> 
> The storyID's that should be returned should be:
> 
> 4385 - 1
> 4513 - 2
> 4382 - 3
> 4533 - 7

Sir, try a self join. Do a standard aggregate query to get the max 
storyIDs, GROUP BY the category ID, and join the max storyIDs to 
the storyIDs of the second instance of the table.

Bob Hall
-- 
"Kanskje, kanskje en gang
 - sier du til meg -
 database, table, query"   RolfJacobSQL

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to