MySQL Select count


The number of rows

SELECT COUNT() The FROM syntax is used to count the number of rows in the data table.

grammar:

SELECT COUNT(column) FROM tb_name

The SQL syntax is used to count the number of rows in a field. COUNT() can not be multiple fields, but can be an asterisk.

Example

uid username
1 John
2 Jack
3 Marry
SELECT COUNT(uid) FROM user
Result
3

Although the count() parameter can be a field name, but if you only want to count the number of data records in the table, for the efficiency user the primary key count(id) or directly use count(*), while avoiding the use of columns.




Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook