0

i have 2 tables

[series]

--------------
ID | ART
--------------
1  | sculptor      
2  | painter
3  | writer
-----------

[artists]

--------------
NAME | ART_IDs
--------------
john | 1
jack | 1,2
jill | 2,1
jeff | 3,1

which I want to join like this:

SELECT se.art, ar.name as artist
FROM series AS se
JOIN artists AS ar ON FIND_IN_SET(se.id , ar.art_ids) > 0

What I get is only the first values:

[result]

-------------------
ART      | ARTISTS
-------------------
sculptor | john
sculptor | jack
painter  | jill
writer   | jeff

Instead of:

[result]

----------------------------
ART               | ARTISTS
----------------------------
sculptor          | john
sculptor,painter  | jack
painter,sculptor  | jill
writer,sculptor   | jeff
5

1 Answer 1

0

Try this:

SELECT GROUP_CONCAT(se.art ORDER BY FIND_IN_SET(se.id , ar.art_ids)) as art, ar.name as artist
FROM series AS se
JOIN artists AS ar ON FIND_IN_SET(se.id , ar.art_ids) > 0
GROUP BY ar.name

If you want to concat column in each group, GROUP_CONCAT can help you.

Check demo in Rextester.

Sign up to request clarification or add additional context in comments.

3 Comments

its result is like this sculptor,sculptor,sculptor | john only with 1 row rest ommited
@FaiqAhmad Check demo.
here is my actual query where table size have two fields 1-id 2-name where my table products have id and size "SELECT group_concat(size.name ORDER BY FIND_IN_SET(eshop_trans.products.size, eshop_trans.size.id)) as size,products.id FROM eshop_trans.products join eshop_trans.size on FIND_IN_SET(eshop_trans.products.size, eshop_trans.size.id)>0 group by size.name "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.