tags:

views:

1397

answers:

3

For example, using the answer for this question:

http://stackoverflow.com/questions/152024/how-to-select-all-users-who-made-more-than-10-submissions "How to select all users who made more than 10 submissions."

select userId
from submission   
group by userId
having count(submissionGuid) > 10

Let's say now I want to know many rows this sql statement outputted. How scalable is the solution for counting the rows of counting the rows?

+2  A: 

In SQL Server you could do

select @@ROWCOUNT

immediately following the query you posted.

ranomore
+2  A: 

Nested queries:

select count(*) from
  (select userId
   from submission   
   group by userId
   having count(submissionGuid) > 10) n

Edited to incorporate mbrierst's comment about needing an alias (the "n" at the end) for the nested subquery. Oracle does not require this, but SQL Server does. Feel free to add a comment regarding usage on other database platforms.

BQ
Sorry, I almost only know SQL Server. That's a nice sounding Oracle feature though, the SQL Server alias requirement always annoys me.
+5  A: 
No need for the alias in Oracle. You do need it in SQL Server. Good catch.
BQ