Skip to content
Advertisement

How can I combine two columns and sort the values alphabetically?

I’m new to programming languages and am trying to get the customers with the longest and shortest names, combine them in a single column, and sort them by longest then shortest names.

Here’s what I have. How can I query to get my desired result in MySQL?

Table is orders

customer_id longest lowest
John Nathaniel John
Michael
Nathaniel

Expected results are:

diff
Nathaniel
John

Advertisement

Answer

It sounds like you want a UNION operator. Something like:

This should find your max and min entries and union them together into a single column named CUSTOMER_ID. Then you just sort them by character length.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement