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 :(
-
Answer:
Have you considered either just counting the rows as you receive them in whatever's consuming this result set, or just using http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows? Is there some reason you need the rowcount to appear as a column in the result set?
Deviprasad Das at Stack Overflow Visit the source
Other answers
Try with: select *, count(*) as row_count from employee group by pk_id
Tudor Constantin
Related Q & A:
- How can I get rid of the "Get IE7 now!" button on the Yahoo Toolbar?Best solution by Yahoo! Answers
- How can I get my Tecumseh engine to get more power and speed?Best solution by Yahoo! Answers
- How can I get an audio alert when I get a new e-mail?Best solution by Yahoo! Answers
- How can I get Bahrain police clearance and were can I apply for it in Australia?Best solution by Yahoo! Answers
- How can I get a text alert when I get an email?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.