Q:

Count how many rows have the same value

How do i write an SQL query to count the total number of a specific num value in the num column of a table.
e.g. select where num = 1
result: 2
+-----+-----+
| NAME | NUM |
+=====+=====+
| SAM  |  1  | 
+-----+-----+
| BOB  |  1  |
+-----+-----+
| JAKE |  2  | 
+-----+-----+  
| JOHN |  4  | 
+-----+-----+

A:

Try
SELECT NAME, count(*) as NUM FROM tbl GROUP BY NAME

SQL FIDDLE

A:

If you want to have the result for all values of NUM:
SELECT `NUM`, COUNT(*) AS `count` 
FROM yourTable
GROUP BY `NUM`

Or just for one specific:
SELECT `NUM`, COUNT(*) AS `count` 
FROM yourTable
WHERE `NUM`=1

A:

FOR SPECIFIC NUM:
SELECT COUNT(1) FROM YOUR_TABLE WHERE NUM = 1

FOR ALL NUM:
SELECT NUM, COUNT(1) FROM YOUR_TABLE GROUP BY NUM

