How to combine results from two columns without union

In my table there are two columns first_name , last_name. I am using union below to combine the results of both columns into one column:

select first_name as name from mytable union all select last_name as name from mytable

It brings the results of both columns under name which is fine. Is there any better and fast approach of doing this without using union?

Not sure how fast is it (probably slower) but you can use concat:

SELECT CONCAT(first_name, ' ', last_name) as name FROM mytable

I can’t advise on the question, but I’m curious why you’d want to bring everything together in a single column - wouldn’t that make common operations like search on last_name and sort orders rather more difficult?

CONCAT doesn’t bring the union of the results in one column like UNION does. I don’t need to combine two columns.

my work here is done :smiley:

4 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.