Getting table data with total counts

Posted by  Tanuj Kumar
 1858  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. 

  1. 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.