Home > database >  Mysql query result branch
Mysql query result branch

Time:10-01

I like the next table
The name col1 col2...
A 1 2...
W e b...

When the select all,
I want to get this kind of resultsThe name col
A 1
A 2
A...
W b
B e
B...

Can you tell me how to query?

CodePudding user response:

 
Select the name, col1 from tab_01
Union all
Select the name, col2 from tab_01
Union all
Select the name, col3 from tab_01

So you can

CodePudding user response:

reference 1st floor qq_37170555 response:
 
Select the name, col1 from tab_01
Union all
Select the name, col2 from tab_01
Union all
Select the name, col3 from tab_01

So you can

So bad, if I were 20 col

CodePudding user response:

refer to the second floor u013731003 response:
Quote: refer to 1st floor qq_37170555 response:

 
Select the name, col1 from tab_01
Union all
Select the name, col2 from tab_01
Union all
Select the name, col3 from tab_01

So you can

This is bad, if I were 20 col?

Really don't know other method, and is the string concatenation, but in the end of the string or the SQL
  • Related