r/mysql • u/o-ooga • Oct 31 '24
question HELP Why is this query not removing duplicated rows ?
i had some duplicated rows in accepted_species table and i thought by adding groupBy and putting the different ids that could be the same for the duplicated rows it'd give me just one row, why is it not working ?
SELECT users.*, user_absence.*, accepted_species.*, prestation.*, species.* FROM users LEFT JOIN user_absence ON users.id = user_absence.userId JOIN accepted_species ON users.id = accepted_species.userId JOIN prestation ON accepted_species.prestationId = prestation.id JOIN species ON accepted_species.speciesId = species.id WHERE users.isDogsitter = 1 AND users.activation = 1 AND prestation.id = 1 AND latitude BETWEEN 0.83580879151064 AND 0.87034026223737 AND longitude BETWEEN 0.014683879073413 AND 0.06721801241413 AND ( species.id IN (1) ) GROUP BY users.id, user_absence.id, accepted_species.id, prestation.id, species.id;
2
u/ssnoyes Oct 31 '24
That GROUP BY means you get one row for each unique combination of ('users.id','user_absence.id','accepted_species.id', 'prestation.id', 'species.id')
1
u/r3pr0b8 Oct 31 '24
does that code eventually produce some SQL that's acceptable to MySQL?
because i can't read that