简体   繁体   中英

Insert into table with multiple select statements in MY SQL

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?

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
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`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM