1

I have two working queries I can't seem to nest.

First one works:

SELECT * FROM accounts WHERE account = 'some_account';

Second works just fine:

SELECT COUNT(*) FROM accounts; 

I would like to join these so that I get the count of accounts from the result of the first query and it would look something like this, but I can't do it.

SELECT COUNT(account) FROM (SELECT * FROM accounts WHERE account = 'some_account');

How would I do this?

4
  • So you want to know the number of rows where account = 'some_account'? Commented Mar 31, 2016 at 8:14
  • yes that's what want Commented Mar 31, 2016 at 8:15
  • The bottom one has COUNT(account) where the middle one has COUNT(*), would that make a difference? Commented Mar 31, 2016 at 8:17
  • 1
    Why not simply select count(*) from accounts WHERE account = 'some_account'? Commented Mar 31, 2016 at 8:19

2 Answers 2

1

Either

SELECT COUNT(account) 
FROM (SELECT account 
      FROM accounts 
      WHERE account = 'some_account');

Or

SELECT COUNT(*) 
FROM accounts 
WHERE account = 'some_account';
Sign up to request clarification or add additional context in comments.

Comments

1
select count(case when account = 'some_account' then 1 else null end) as Count
FROM accounts

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.