How to count a record count

How to count a record count

Most often it is necessary to find out a record count when programming web resources in tables of the database working under control of MySQL DBMS. For this operation in the SQL language there is a special function. The request with e use can be modified adding of additional conditions of filtering - it will allow to receive not only total number of records, but also the quantity meeting additional conditions.

Instruction

1. Use the Count function in combination with the Select command for drawing up request which should return a record count in the table of the database interesting you. If to transfer to this function as parameter an asterisk (* - vayldkard), all records which value differs from Null will be counted. Except Count in request, as usual for the Select command, the name of the table should be specified. For example, for clarification of a record count in the table with the name allCustomers the request can be written so: SELECT COUNT (*) FROM allCustomers;

2. If it is necessary to receive a record count by which in a certain field of the table some value is placed though, except Null value, enter the name of this field instead of an asterisk as Count. Let's tell, the creditSum field of the table allCustomers is intended for information storage about the sum of the issued credits to each of the clients listed in this table. Then the request for number of records from the first step can be modified that it returned the number of clients to whom the credit was issued. The request after editing so can look: SELECT COUNT(creditSum) FROM allCustomers;

3. For calculation of records with unique value in the defined sex add Distinct to his name as Count. For example, if the table contains the repeating records which concern different clients in the field of clientName, then the number of clients who are mentioned in them it is possible to receive with use of such request: SELECT COUNT(DISTINCT clientName) FROM allCustomers;

4. In the presence of access to the PhpMyAdmin application everything considerably becomes simpler as need to make the SQL query independently disappears. After authorization in this program pass to the page with information on the database containing the necessary table - select its name in a drop-down list of the left frame. The list of tables of this base in which column "Records" you also will find required value for each of them will be loaded into the right frame.

Author: «MirrorInfo» Dream Team


Print