GETTING TABLE DATA WITH TOTAL COUNTS

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
MYSQL 
 1181  View(s)
Ratings:
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. 

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Getting table data with total counts

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!