reorder table from 4 column to 1 column

Hi,

Kindly assist how can we requery 4 columns to be place to a single column.

table called scores
columns:
singing dancing eating voice
  10        9           8       10


output to a single column:
10
9
9
10

Thanks.
EdwardPeterAsked:
Who is Participating?
 
Renante EnteraConnect With a Mentor Senior PHP DeveloperCommented:
Hi EdwardPeter!

You can simply do it using UNION ALL.  

Here's the query :

Select singing as ColumnName
From TableName
UNION ALL
Select dancing as ColumnName
From TableName
UNION ALL
Select eating as ColumnName
From TableName
UNION ALL
Select voice as ColumnName
From TableName

Hope this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0
 
Jonathan KellyConnect With a Mentor Commented:
this might be one way

Select singing from tbl
UNION
Select dancing from tbl
UNION
Select eating from tbl
UNION
Select voice from tbl



0
 
lluthienConnect With a Mentor Commented:
although you might want to consider adding an extra column to be able to identify where the scores come from,
like so:

Select 'singing' as sourcecolumn, singing as ColumnName
From TableName
UNION ALL
Select 'dancing' as sourcecolumn, dancing as ColumnName
From TableName
UNION ALL
Select eating' as sourcecolumn, eating as ColumnName
From TableName
UNION ALL
Select 'voice' as sourcecolumn, voice as ColumnName
From TableName


so your result is:
sourcecolumn columname
singing          10
dancing           9
eating             9
voice             10

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
EdwardPeterAuthor Commented:
entrance2002,

How can we give the column a name?

Thanks.
0
 
Renante EnteraSenior PHP DeveloperCommented:
Hi EdwardPeter!

Thanks for accepting my comment as the answer.  I'm glad that I have helped you.

Hope to help you again...


Regards!
eNTRANCE2002 :-)
0
 
lluthienCommented:
saw that one coming
EdwardPeter :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.