Home SQL Basic SQL Count
07.09.2010
Main Menu
Programming
.NET Controls
Operating System
Databases
Articles
Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: StumbleUpon Add to: Slashdot Add to: Yahoo Add to: Technorati Add to: Google
SQL Count

The SQL Count is a handy function allowing you to quickly total count number of records in a table. To use the SQL Count function you can use the following syntax:

SELECT COUNT("column_name")

FROM "table_name"

Table: Student

StudentID LastName FirstName DOB CourseFees CourseName
1 John Astone 07/15/1976 1000.00 Accountant
2 Bob Eastwood 02/13/1935 1500.00 Economic
3 Jane Hollywood 03/23/1939 2000.00 IT
4 Bob Eastwood 03/19/1980 3000.00 Economic


For example to find the total number of student in the student table you would issue the following SQL statement:

SELECT COUNT
(LastName) AS 'Total Number of Student'
FROM Student

RESULT:

 

Total Number of Student

4

You can also use the DISTINCT keyword in conjunction with the count function get the return distinct result. For example if we to find total number of unique course the student has enrolled in we would issue the following SQL statement:

SELECT COUNT
(DISTINCT CourseName) AS 'Total Course'
FROM Student

RESULT:

Total Course

3

 

 



Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."