How To Count The Number Of Records

Table of contents:

How To Count The Number Of Records
How To Count The Number Of Records

Video: How To Count The Number Of Records

Video: How To Count The Number Of Records
Video: How to Count the Number of Unique Values in a List in Excel : Using Excel 2024, November
Anonim

Most often, it is necessary to find out the number of records when programming web resources in the tables of a database running under the control of the MySQL DBMS. There is a special function in SQL for this operation. A query using it can be modified by adding additional filtering conditions - this will allow you to get not only the total number of records, but also the number that meets additional conditions.

How to count the number of records
How to count the number of records

Instructions

Step 1

Use the Count function in conjunction with the Select command to create a query that returns the number of records in the database table you are interested in. If an asterisk (* - wildcard) is passed to this function as a parameter, all records with a value other than Null will be recalculated. In addition to Count, the query, as usual for the Select command, must contain the name of the table. For example, to find out the number of records in a table named allCustomers, the query can be written as follows: SELECT COUNT (*) FROM allCustomers;

Step 2

If you need to get the number of records that have at least some value other than Null in a certain field of the table, specify the name of this field instead of an asterisk in the Count function. Let's say the creditSum field of the allCustomers table is intended to store information about the amount of loans issued to each of the customers listed in this table. Then the request for the number of records from the first step can be adjusted so that it returns the number of customers to whom the loan was issued. The query looks like this after editing: SELECT COUNT (creditSum) FROM allCustomers;

Step 3

To count records with a unique value in a specific field, add Distinct to its name in the Count function. For example, if a table contains duplicate records that refer to different customers in the clientName field, then the number of customers mentioned in them can be obtained using the following query: SELECT COUNT (DISTINCT clientName) FROM allCustomers;

Step 4

If you have access to the PhpMyAdmin application, everything is greatly simplified, since there is no need to compose an sql query yourself. After authorization in this program, go to the page with information about the database containing the required table - select its name in the drop-down list of the left frame. The list of tables of this database will be loaded into the right frame, in the "Records" column of which you will find the required value for each of them.

Recommended: