select max(storyID), storyCategoryID from newsStories where storyCategoryID > 0 group by storyCategoryID
----- Original Message ----- From: "Christopher Oson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, November 15, 2001 6:31 AM Subject: Easy SQL query?? > Good Day, All, > > Given: > > 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 > > HTH, > > Christopher Oson > > --------------------------------------------------------------------- > 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 > > --------------------------------------------------------------------- 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