Jump to content

Is it possible to get several columns to stack in single result column?


tarsier

Recommended Posts

Hello All,

I have a SQL question and hope someone can point me in the right direction. I would like to do a query and have several columns reduce into a single result column. I will try to give a simple example here.

 

I have a table that looks something like this

 

account_name

account_phone1

account_phone2

name1

555-555-1111

555-555-2222

name2

555-555-3333

555-555-4444

 

 

I would like to do a search like:

SELECT {SQL MAGIC} WHERE account_name = 'name1'

 

and get the result

 

account_name

phone

name1

555-555-1111

name1

555-555-2222

 

Where phone1 and phone2 are combined into a single column. Is this possible? It will greatly reduce the complexity of my program.

 

Thanks for any input you have.

 

- Dave

 

 

There are several ways to do this, but probably the easiest would be a union

 

SELECT account_name, account_phone1 AS phone
FROM account
WHERE account_name = 'name1'

UNION ALL

SELECT account_name, account_phone2
FROM account
WHERE account_name = 'name1'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.