Hi I'm having trouble with a subquery and really need some help.
I'm trying to count to count the number of beats sold by a particular producer.

So the first thing I did was SELECT all the beats sold by that producer so I wrote the code

select name, production_no
from beats
where availability = 'Sold'
and p_staffid = 1;

'p_staffid' is the id number for the particular producer and the 'production_no' is the primary key for the beat itself. I have tested this code and it works perfectly.

But how do I count the results?

The COUNT function will return the number of rows returned by the query which is what I think you are trying to do. The COUNT function requires a column to count as a parameter, so your query will look something like this:

select COUNT(name) as number_sold
from beats
where availability = 'Sold'
and p_staffid = 1;
commented: Exactly what I needed. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.