-   Programming (
-   -   SQL statements howto -- 3 columns input but 2 columns output (

fhleung 07-04-2012 05:38 AM

SQL statements howto -- 3 columns input but 2 columns output
Hi folks, this is my first time to post in this programming sub forum.

I got questions on SQL statement, please visit:

Snark1994 07-04-2012 06:31 AM

It is far more normal to post your problem in your own post - for example, if that site goes offline, there's no record of your question.


I got 3 columns, name, col1, col2, I want to output 2 columns only
col1== col2 OR col1!=col2 in each row
but my final output only 2 column

        name        col1        col2
row1        A        1        1
row2        B        2        22
row3        C        3        333
row4        D        4        4


        name        column       
row1        A        1       
row2        B        2       
row3        B        22       
row4        C        3       
row5        C        333       
row6        D        4

is what you have on the link,

and the answer is:


(SELECT name, col1 FROM `test`) UNION (SELECT name, col2 FROM `test`)

fhleung 11-28-2012 11:36 PM

Dear Snark1994,

Thank you for the repsond. Thank you for the keyword UNION

It is work and HELPFUL! Thank you once again!

Snark1994 11-29-2012 11:45 AM

No problem, glad it helped. Please mark the thread as "SOLVED" so others know it contains a solution.


All times are GMT -5. The time now is 11:20 AM.