Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql count unique row values

TABLE quotation

id  clientid
1   25
2   25
3   25
4   25
5   26

How can I query how many different clients exist in TABLE quotation? I don't want duplicate entries to be counted more than once.

I need the answer to be 2, in 1 row, because the only non-duplicated entries are (25, 26).

like image 373
love Avatar asked Nov 09 '10 09:11

love


People also ask

How do I count unique values in MySQL?

To count distinct values, you can use distinct in aggregate function count(). The result i3 tells that we have 3 distinct values in the table.

How do I count unique rows?

We can use SQL Count Function to return the number of rows in the specified condition. The syntax of the SQL COUNT function: COUNT ([ALL | DISTINCT] expression); By default, SQL Server Count Function uses All keyword.

Does Count * Return the number of rows?

Answer: COUNT function is an aggregate function that can be used in 3 ways. COUNT(*) – This would COUNT all the rows returned by the SELECT QUERY.

How can I count distinct records in SQL?

The COUNT DISTINCT function returns the number of unique values in the column or expression, as the following example shows. SELECT COUNT (DISTINCT item_num) FROM items; If the COUNT DISTINCT function encounters NULL values, it ignores them unless every value in the specified column is NULL.


2 Answers

select count(distinct clientid) from quotation

read more

like image 185
Haim Evgi Avatar answered Sep 20 '22 16:09

Haim Evgi


I find a way out

SELECT COUNT(*) as total FROM (SELECT COUNT(*) FROM quotation GROUP BY
clientid) t1
like image 44
love Avatar answered Sep 17 '22 16:09

love