How To Use SELECT Statement to Count the Number of Rows

Q

How To Use SELECT Statement to Count the Number of Rows? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY

✍: FYIcenter.com

A

If you want to count the number of rows, you can use the COUNT(*) function in the SELECT clause. The following tutorial exercise shows you some good example:

mysql> SELECT COUNT(*) FROM fyi_links;
+----------+
| COUNT(*) |
+----------+
|        7 |
+----------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(*) FROM fyi_links 
   WHERE url LIKE '%fyi%';
+----------+
| COUNT(*) |
+----------+
|        3 |
+----------+
1 row in set (0.01 sec)

So there are 7 rows in total in table "fyi_links", and 3 rows that have 'fyi' as part of their url names.

2007-05-11, 5021👍, 0💬