0

i have question about INNER JOIN and EXPLODE. How to inner join table 'group' in table 'users', explode 'group_id', and display group_id as 'group_name'? Sorry for my poor English. Thanks before.

Image below include table value and display example in browser.

tables and display

Barmar
  • 741,623
  • 53
  • 500
  • 612
Aruna
  • 11
  • that's why you don't save it delimited in the first place, your table needs to be normalised – Kevin Mar 03 '20 at 03:18
  • Please [use text, not images/links, for text--including tables & ERDs](https://meta.stackoverflow.com/q/285551/3404097). Use images only for what cannot be expressed as text or to augment text. Please show any part(s) you can do. Don't expect us to write your code. For code questions give a [mre]. Use enough words, sentences & references to parts of examples to clearly & fully say what you mean. – philipxy Mar 03 '20 at 03:46
  • The duplicate link only does the first part of your problem. But 1. you have shown no attempt to answer this 2. this is an easily found faq; googling 'site:stackoverflow.com mysql replace id list by name list' ... [How to replace comma separated department ids with their name respectively?](https://stackoverflow.com/q/29484913/3404097) 3. getting rid of a list of values is a faq 4. forming a list of values is a faq 5. you don't mention anything about trying to use the duplicate link. See [ask], other [help] links, hits googling 'stackexchange homework' & the voting arrow mouseover texts. – philipxy Mar 03 '20 at 04:24
  • If it's mysql version 8 then you can try : `WITH grp (id,group_name) AS ( SELECT '1' , 'Admin' UNION ALL SELECT '2' , 'Operator' UNION ALL SELECT '3' , 'Member' ) , usr(id,username,name,group_id) AS ( SELECT 1 id, 'joe' username,'Joe Duran' AS name, '1' group_id UNION ALL SELECT 2,'annie','Annie Marie','2' UNION ALL SELECT 3,'mich','Micheal','2,3' ) Select *,GROUP_CONCAT(grp.group_name) From usr, grp Where FIND_IN_SET(grp.id ,usr.group_id) Group by usr.id order by usr.id` – Fact Mar 03 '20 at 04:58
  • 1
    @philipxy I've added another duplicate link that shows how to use `GROUP_CONCAT()` to create the comma-separated list in the result. – Barmar Mar 03 '20 at 14:49
  • 1
    @philipxy And now I added the question you found, which shows both. – Barmar Mar 03 '20 at 14:49

0 Answers0