0

I have the result from a query like:

+------------------+------------+ | meta_key | meta_value | +------------------+------------+ | Destination Name | Shivapuri | | Destination Date | 26/03/2012 | +------------------+------------+ 

I am trying to write a select statement with the Column name as Destination Name and Destination Date whose respective values are Shivapuri and '26/03/2012'. How is this possible to do with a query in MY SQL?

4
  • 2
    This is called a pivot table and has been answered many times before on SO: stackoverflow.com/questions/7674786/mysql-pivot-table Commented Apr 6, 2012 at 11:12
  • Pivot is rather unneeded, Since by the nature of the structure, there is only going to be one destination name and destination date. Commented Apr 6, 2012 at 11:27
  • How many name and date are going to be there Commented Apr 6, 2012 at 11:35
  • What is the full structure of the table? Commented Apr 6, 2012 at 11:36

2 Answers 2

1

Something along these lines should do it -

SELECT GROUP_CONCAT(IF(meta_key = 'Destination Name', meta_value, NULL)) AS `Destination Name`, GROUP_CONCAT(IF(meta_key = 'Destination Date', meta_value, NULL)) AS `Destination Date` FROM tbl_name GROUP BY record_identifier 
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT (CASE WHEN meta_key = 'Destination Name' THEN meta_value END) as name, (CASE WHEN meta_key = 'Destination Date' THEN meta_value END) as date FROM `yourtable` 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.