I’m trying to create a simple message feature for my website but I couldn’t get distinct datas from 2 columns (**from** column and **to** column)

you see examples datas on the picture
how can I get the return “1,4,23,45,345”?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should to union both columns and then filter for distinct values:
if you really need all in a comma separate string, use GROUP_CONCAT([DISTINCT] aggregation function.
EDITED:
You should mark as solution Gerald answer. After test union operator and reread mysql union operator documentation, by default, mysql filter for distinct values:
then, the final query is:
Notice that
distinctis not mandatory.Only if you need a comma sparate string the first solution is necessary: