INNER JOIN mysql
I have this code which I use to get the number of subscribers:
SELECT provider_id,subcat_id, COUNT(user_id) AS subscribers
FROM subscribers WHERE subcat_id=5
AND provider_id=provider_id
GROUP BY provider_id
ORDER BY subscribers DESC LIMIT 10
provider_id is a foreign key to the providers table which contains the
provider_name.
How can I get the results which obtains the foreign key value for
provider_id and replaces it with the provider_name from table providers? I
tried an inner join, but it didn't work. It is probably a syntax error as
my select query is a bit complicated.
The results I get now are:
provder_id | subcat_id | subscribers
2 | 5 | 5
4 | 5 | 3
1 | 5 | 1
However, what I want is:
provder_id | provider_name | subcat_id | subscribers
2 | Alex | 5 | 5
No comments:
Post a Comment