1

As the title states, I want to count the amount of rows in a column using a SQL query in PHP

Kriss0612
  • 57
  • 1
  • 10
  • possible duplicate of [Most efficient way to get table row count](http://stackoverflow.com/questions/933565/most-efficient-way-to-get-table-row-count) – Mmmh mmh Dec 07 '14 at 14:24

1 Answers1

1

If you just want the number of rows, you can use the count(*) function:

SELECT COUNT(*) FROM my_table

If you want the number of values (i.e., excluding nulls), you can use count on the column:

SELECT COUNT(my_column) FROM my_table

If you want the number of different values, you can add the distinct keyword:

SELECT COUNT(DISTINCT my_column) FROM my_table
Mureinik
  • 297,002
  • 52
  • 306
  • 350