Reputation: 95
SELECT Count the rows that are in this query --> (SELECT Family FROM BIRD GROUP BY Family) FROM BIRD
Every time I just try and count that sub query I get an error saying that there is more than one resulting value. I'm not sure how to count up the rows resulting from a sub query, any ideas?
Upvotes: 2
Views: 871
Reputation: 1316
Assuming you just want a count of the rows, let's have a go at this:
SELECT COUNT(*) FROM (SELECT Family FROM BIRD GROUP BY Family)
Upvotes: 0
Reputation: 2952
try this for getting count, there is no need to sub-query for counting
select count( distinct family) from bird;
Upvotes: 0
Reputation: 18747
Try this:
SELECT Count(*) as FamilyCount
FROM (SELECT Family FROM BIRD
GROUP BY Family) Families
Count()
returns the number of items in a group. Read more here.
Upvotes: 1
Reputation: 311573
You could put this sub-query in the from
clause:
SELECT COUNT(*)
FROM (SELECT family
FROM bird
GROUP BY family) t
But if you're just trying to get the number of different bird families you don't really need a subquery:
SELECT COUNT (DISTINCT family)
FROM bird
Upvotes: 2