moimoi
moimoi

Reputation: 201

MYSQL How would you get distinct along with its count

How would you get list of each distinct UUID along with its count

SELECT DISTINCT uuid, COUNT(uuid) as count FROM log;

id  uuid
|  1 | a846        
|  2 | a846
|  3 | a846
|  4 | a846
|  5 | b307
|  6 | b307
|  7 | b307                                                               
|  8 | b307
|  9 | b307                                                           
| 10 | b307

Expected result

a846 4
b307 6

Upvotes: 0

Views: 37

Answers (1)

GMB
GMB

Reputation: 222402

Just use group by!

select uuid, count(*) cnt from log group by uuid

Upvotes: 4

Related Questions