M
M
Manager12019-01-09 21:42:48
SQL
Manager1, 2019-01-09 21:42:48

How to correctly count the number of unique values ​​in a field in a query?

Good afternoon.
There is a table table1 with fields id, name, size.
In the size field, the values ​​are text. You need to count and display the number of unique values.
For example, we have such values ​​as small, medium, large, medium, large, very large. Should get 4 as a result.
I tried with such a construction, but it gives 0.
SELECT SUM(DISTINCT size) FROM `table1`;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaximKAI, 2019-01-09
@Manager1

SELECT COUNT(DISTINCT size) FROM table1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question