Irma Elita Irma Elita - 5 months ago 11
SQL Question

How to count rows using group by

I have a table like this.



---------
| block |
---------
| A1 |
| A1 |
| A2 |
| A3 |
---------





I want to count found rows using group by, so it would return value like this.


--------------
| total_block|
--------------
| 3 |
--------------





What is the correct query to show results like that? I have already tried using SQL_CALC_FOUND_ROWS but it return values = A1, A2, A3. Thank you.

Answer

Looks like you just want the number of different blocks:

select count(distinct block) as total_block from tablename
Comments