2

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?

3
  • 2
    Why not just select count(*) from (select family form bird group by family)? Commented Mar 16, 2014 at 7:18
  • Thanks heaps, I'm new to sql and wasnt aware that you could "FROM" to something like that. If you put it as an answer I'll accept it. Commented Mar 16, 2014 at 7:22
  • Others already did. Don't worry, SQL becomes an art and you will get it. Commented Mar 16, 2014 at 7:23

4 Answers 4

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

try this for getting count, there is no need to sub-query for counting

select count( distinct family) from bird;

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.