I'm trying to retrive data from MySQL data base.
The structure of the table (Tab_1
) there is:
id key value
1 address xyz
1 post_code 120
1 country CA
As you can see this is actually order details information.
I want to convert the key column to be an actual column and the value to be the value of this column. meaning:
id address post_code country
------------------------------------
1 xyz 120 CA
Where id=1
is the key of this order.
The table in MySQL can not be changed. Its part of a close system that we use (WordPress plugin) I just want to write a query that gets some data from it...
My goal is to use it in a join where it would be easier to get the data:
Select x.address ,x.post_code, x.country
from orders
join (...) as x using (order_id=id)
where order_id=1
It should give:
address post_code country
------------------------------------
xyz 120 CA
As you can see it suppose to get all fields of x which is the address,post_code,country etc.
the ...
in the join is where I need to put the query that convert Tab_1
to a readable stracture for the join.
How can I do that?