If you're using MS SQL Server (I'm not sure how many other dbs support this)
you can use the TOP keyword to specify how many records to return. In your
case, it would be:
Select TOP 3 SUM(Quantity) AS TopBooks, BookID
>From OrderItems
GROUP BY BookID
ORDER BY TopBooks DESC
The TOP keyword also supports selecting a percentage instead of a number of
records.
Josh Black
----- Original Message -----
From: "Brian Ingram" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, April 29, 2000 4:19 PM
Subject: SQL Question?
> Query:
>
> Select SUM(Quantity) AS TopBooks, BookID
> >From OrderItems
> GROUPBY BookID
> ORDER BY TopBooks DESC
>
>
> Here is what i get when i run this query(show below). All I want is the
top 3 books returned. How can i do this with SQL?
>
> TopBooks BookID
> 70 15
> 8 3
> 5 4
> 4 1
> 1 21
> 1 18
> 1 13
> 1 10
>
> As always, thanks in advance for your help. This message board has saved
me numerous times.
>
> Brian
> -----------------------------------------------
> FREE! The World's Best Email Address @email.com
> Reserve your name now at http://www.email.com
>
>
> --------------------------------------------------------------------------
----
> Archives: http://www.eGroups.com/list/cf-talk
> To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
>
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.