SELECT DISTINCT still showing duplicates

Yes, there are so many questions about this, but I was looking for half an hour, and I still have to find a solution.

So, I have a table like this: enter image description here

And this is my request:

SELECT DISTINCT rengasID,leveys FROM renkaat ORDER BY leveys ASC

And as a result, I get:

enter image description here

If you have an idea, I fill in the field with it, but it still has duplicates.

What am I doing wrong?

+4
source share
3 answers

If you need different leveys, just select this field:

SELECT DISTINCT leveys
FROM renkaat
ORDER BY leveys ASC

rengasid has a different meaning for each row.

The sentence distinctapplies to all columns returned regardless of the brackets.

EDIT:

If you need regasidthe result, use group by:

select leveys, min(regasid) as regasid
from renkaat
group by leveys
order by leveys asc;

. , , group_concat(). , .

+7

rengasID - . , rengasID leveys.

, MySQL , .

, , "leveys" ( , ) . , . , group by id .

+2

This is because you choose a combination of rengasIDand leveys. And what you get as a result is a great combination of the two.

To achieve what you are trying, see @GordonLinoff answer.

0
source

Source: https://habr.com/ru/post/1526554/


All Articles