A
A
Alexander2015-09-17 14:20:01
PHP
Alexander, 2015-09-17 14:20:01

How to remove duplicates when using Left Join?

Good afternoon, task: display tags for the image.
I know to use GROUP_CONCAT but don't know how to adapt it.
Three imgage tables are used - images, key relationship (imgId, tagId) and tag - the tags themselves

SELECT * FROM image
LEFT JOIN key ON key.ImgId= image.imId
LEFT JOIN tag ON tag.id = key.tagId where author='1'

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nozzy, 2015-09-18
@alexis78i

SELECT
image.imId,
GROUP_CONCAT(CAST(tag.id as VARCHAR(10)))
FROM image
LEFT JOIN key ON key.ImgId= image.imId
LEFT JOIN tag ON tag.id = key.tagId where author='1'
GROUP BY image.imId

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question