Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Counting Records

September 13, 1998

It is also very easy to count the number of records that meet a certain criteria. This function is performed with the COUNT operator and follows the syntax:

    SELECT COUNT (column_name)
    FROM table_name
    WHERE where_clause [optional];

In other words, to count the number of employees in the EMPLOYEES table, you would use:

    SELECT COUNT (EMP_NAME)
    FROM EMPLOYEES;

which would return the following:

    COUNT (EMP_NAME)
    -----------------
    3
    -----------------

Note that sometimes, it is preferable to use SELECT COUNT(*) instead of specifying a column_name. This is because the COUNT operator does not consider columns with null values. Thus, if you specified a column_name and one of the rows in that table had a null value for column_name, your count would be off. Using "*" assures that all rows are counted even if they include null values. And by the way, most implementations of SQL will also require you to use the DISTINCT operator if you specify a column_name.

Maximums and Minimums
Introduction to Databases for the Web | Table of Contents
Distinct


Up to => Home / Authoring / DB / Intro




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers