I have a MySQL table like the following
prod price1 price2 price3
---- ---- ---- ----
AA 100 200 400
BB 200 300 655
How to write a query in MySQL so that the table appears vertically like this?
prod price
---- -----
AA 100
AA 200
AA 400
BB 200
BB 300
BB 655
2
Answers
You could use
UNION ALL
to do this:Replace your
table
with the actual name of yourtable
. This query will select each product with each of its prices and combine them into a single result set.