Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select from multiple columns in separate rows

Author  Topic 

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2011-03-08 : 12:02:09
Hi,
I have table which contains columns Name1, Name2, and Name3.
How would I do a select that returns individual rows for each Name. So if my table has 2 rows, I want my Select to return 6 rows. I don't need to be able to tell the columns apart.

Something like:
Select (Name1,Name2,Name3) as Name from mytable.

Thanks.

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2011-03-08 : 12:06:26
Just off the top of my head (our server is down so I can't test)

select Name1 from mytable
UNION
select Name2 from mytable
UNION
select Name3 from mytable



Hey, it compiles.
Go to Top of Page

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2011-03-08 : 12:16:37
The above worked. Thank you.
Go to Top of Page
   

- Advertisement -