I made the following query that get the MIN(id) of duplicate path values in the table movies:
SELECT m.id, m.user_id , m.path
FROM movies m
INNER JOIN (
SELECT Min(id) as movie_id, path, COUNT(*)
FROM movies
WHERE importer LIKE '%AS%'
GROUP BY path
HAVING COUNT(*) > 1) temp
ON temp.path = p.path
AND temp.movie_id = m.id
AND importer LIKE '%AS%'
I got this result:
id | user_id | path |
------------------------------------
2 | 1234 | XXXX |
8 | 4231 | BBBB |
The problem is that I have another movie with the same path but dont appear because the MIN() and the GROUP BY path
I want to group the path but dont exlude the other path because I do MIN(id)
This is the expected result:
id | user_id | path |
------------------------------------
2 | 1234 | XXXX |
8 | 4231 | BBBB |
5 | 3421 | BBBB |
What Im doing wrong?
@Tim Biegeleisen
The problem is with that query I obtain duplicated paths with same user_id :
id | user_id | path |
------------------------------------
3523 12287 asd
3524 12287 asd
3525 12287 asd
I should obtain the min id for each grouped path.