L
L
lemonlimelike2017-10-01 12:50:58
MySQL
lemonlimelike, 2017-10-01 12:50:58

Why doesn't DISTINCT work?

I have a sql query

SELECT * FROM video_category INNER JOIN category ON category.id = video_category.category_id INNER JOIN video ON video.id = video_category.video_id WHERE video_category.category_id = :id ORDER BY video_category.video_id DESC

The request displays data, but for some reason they are repeated
59d0ba44ce9f3504815629.jpeg
Changed the request to
SELECT DISTINCT * FROM video_category INNER JOIN category ON category.id = video_category.category_id INNER JOIN video ON video.id = video_category.video_id WHERE video_category.category_id = :id ORDER BY video_category.video_id DESC

Those. added DISTINCT, it should remove duplicate entries, but for some reason this does not happen, what's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
toxa82, 2017-10-01
@lemonlimelike

DISTINCT is distributed to all columns specified in SELECT, and at you id does not repeat. Use GROUP BY on the columns you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question