Getting the total quantity of each item in a table

Good day,

I am working in an online website for selling books.
There is a table where the sold books are stored, like this:

Purchases

id | int - autoincrement
Date
CustomerID (foreing key to table Customers)
BookID (foreign key to table Books)

How can I calculate the total quantity of sold books of each one?
For instance, having ‘n’ books, how many BookID = 1 to n have been sold (how many of each one)?

Thanks a lot!!!

SELECT
    BookID
  , COUNT(*) AS Total
FROM Purchases
GROUP BY BookID

Hi guido2004,

One last question please. Where are the result stored and how can I read them?
I understand I have to run this query and assign a variable to the result.
Is this result an array, having the totals of each BookID per rows?

Thanks a lot for your answer!!

What language are you using? As that question may be better suited in the appropriate forum. If you are using PHP, are you utilizing PDO, MySQLi, MySQL?

Sorry, I am using PHP and MySQL.

Thanks a lot!

Okay, well then you can utilize several different options.
[fphp]mysql_ fetch_ array[/fphp], [fphp]mysql_ fetch_ assoc[/fphp], and [fphp]mysql_fetch_row[/fphp]

All of the above options have examples of how to use them.