Answer the question
In order to leave comments, you need to log in
How to display the number of unique records in mysql?
Good afternoon.
There is a table with goods. Each has an article, name, etc.
The task is: to count the number of records in the table, grouped by article and with a unique name.
That is, if we have 2 records in the table, but they have the same name, we need to display 1 in COUNT.
To begin with, I simply made a query in order to get the number of records (not unique)
SELECT artikul, COUNT(*) AS CNT FROM items GROUP BY articul
SELECT artikul, COUNT(DISTINCT name) AS CNT FROM items GROUP BY articul
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question