Column Distinct Values In A Specific Column With MYSQL


Column Distinct Values In A Specific Column With MYSQL

The code below can be used to get the distinct values in a column. For example, if there was 4 entries which had dog, cat, cat and monkey...the result would be 3.

Objective:
Select distinct values in a specific database table.
 
Procedure:
$command = "SELECT count(DISTINCT columnname) as cnt FROM tablename WHERE id='$id' ORDER BY date ASC ";