SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

SQL COUNT Command

We can count the number of records in a table with different combinations. Let us first count the total number of records in the table with this count command.


SELECT count( * ) as total_record FROM student



This will display total records under the name total_record in the table student. Now we can add some condition to this SQL to count the records with different conditions. Let us find out the number of students in class Four in out table. 


SELECT count( * ) as total_record  FROM `student` WHERE class = 'four'
Related Tutorial
SQL Group by
MySQL Max
MySQL Average
MySQL Sum
Copy data to new table
SQL Left Join


This will return the count of students in class four only. Here since we are displaying only one count for a fixed class so we can use this way. We may require to display total of each class in a table so here we have to use GROUP BY clause to display totals of all the tables.

Discuss this tutorial at forum

List of SQL Tutorials


 
Scripts
PHP
JavaScript
HOME
SQL Tutorial List
SQL (Home)
SQL Commands
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.