MySQL join together 2 columns without duplicates
MySQL join together 2 columns without duplicates
I have a tablethat looks like following:
username is_superuser last_login name roles roles_for_groups
rob 0 21-06-18 CCTSAT dev full_access
rob 0 21-06-18 CCTSAT ReadOnly ReadOnly
rob 0 21-06-18 CCTSAT ReadOnly full_access
rob 0 21-06-18 CCTSAT ReadOnly_Setup SampleReadOnly
rob 0 21-06-18 CCTSAT ReadOnly_Setup full_access
rob 0 21-06-18 CCTSAT full_access SampleReadOnly
rob 0 21-06-18 CCTSAT full_accessCC full_accessCC
rob 0 21-06-18 CCTSAT full_accessGLE SampleReadOnly
rob 0 21-06-18 CCTSAT full_accessGLE full_accessCC
rob 0 21-06-18 CCTSAT prod_full_access SampleReadOnly
rob 0 21-06-18 CCTSAT prod_full_access full_accessCC
and I would like to merge together the columns roles and roles for groups in a way that if in the column roles for group there is a role that is not present in roles it will be added.
How can I achieve this?
1 Answer
1
Use a UNION
query to get them both in the same column. By default, UNION
removes duplicates from the result.
UNION
UNION
SELECT username, is_superuser, last_login, name, roles
FROM yourTable
UNION
SELECT username, is_superuser, last_login, name, roles_for_groups
FROM yourTable
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you add a result sample to clarify your question?
– Norbert van Nobelen
42 mins ago