On Thursday 15 November 2001 13:03, 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
try:
SELECT MAX(storyID), storyCategoryID, title
FROM newsStories
GROUP BY storyCategoryID;
hth
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
/*
HR 3128. Omnibus Budget Reconciliation, Fiscal 1986. Martin, R-Ill.,
motion that the House recede from its disagreement to the Senate
amendment making changes in the bill to reduce fiscal 1986 deficits.
The Senate amendment was an amendment to the House amendment to the
Senate amendment to the House amendment to the Senate amendment to the
bill. The original Senate amendment was the conference agreement on the
bill. Agreed to. -- Albuquerque Journal
*/
---------------------------------------------------------------------
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