Deviprasad Das
Deviprasad Das

Reputation: 4363

How can I get the rows along with row count in SQL?

I have written the following query:

select 
    *, 
    count(pk_id) as row_count
from employee 
group by 
    pk_id

But I am not getting 1 as the row_count value for every column. How can I get the total number of rows returned as the result of the query? Can someone please help?

And one more thing is I don't want to write any subquery :(

Upvotes: 1

Views: 1682

Answers (2)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239664

Have you considered either just counting the rows as you receive them in whatever's consuming this result set, or just using FOUND_ROWS? Is there some reason you need the rowcount to appear as a column in the result set?

Upvotes: 1

Tudor Constantin
Tudor Constantin

Reputation: 26861

Try with:

select 
    *, 
    count(*) as row_count
from employee 
group by 
    pk_id

Upvotes: 0

Related Questions