Home > DeveloperSection > Forums > Getting table data with total counts
Tanuj Kumar

Total Post:134

Points:940
Posted on    May-18-2013 1:21 AM

 MYSQL MYSQL 
Ratings:


 1 Reply(s)
 860  View(s)
Rate this:
Hi Mindstickians!

I am having following table (student)

sid sname   branch  semester
  1   Vijay   CSE      6
  2   Ajay    MECH     4
  3   Riteh   CSE      6 
  4   Nutan   CSE      6
  5   Riya    ETC      4
  6   Ritu    CSE      6 

Here I want to fetch all record and total fetched record count for that i'm using following query, but this is not able to fetch all records

select *,count(sid) from students
How can we do this?

Please help!
Thanks in advance. 



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-18-2013 8:27 AM

Hi Tanuj!

You can achieve as following using sub query 

select *,(SELECT COUNT(*) FROM students) totalCOunt from students
using CROSS JOIN

select a.*, b.totalCOunt 
from students a, (SELECT COUNT(*) totalCOunt FROM students) b

It may be helpful for you.

Don't want to miss updates? Please click the below button!

Follow MindStick