在单个 MySQL 查询中获取 Post ID 和 POST META

Get Post ID with POST METAs in single MySQL query

来自 POSTS->ID,我想要 post_type = 'product' 的前 12 个 ID 通过该 ID 关联,我想获取所有 POST META。

我正在使用这个 MySQL 查询,但它不起作用:

SELECT posts.ID, postmeta.meta_key, postmeta.meta_value FROM `wp_u8gwgg_posts` as posts

INNER JOIN wp_u8gwgg_postmeta as postmeta on posts.ID = postmeta.post_id

WHERE 

posts.`post_type` = 'product' AND 
posts.post_status = 'publish'

ORDER BY posts.ID

它给了我多余的 post_id 数据。:

Post ID | Meta Key       | Meta Value
++++++++++++++++++++++++++++++++++++++
12      | _sku           | 18945236
12      | _price         | 1569.36
12      | _regular_price | 1496.20

我想要的结果是:

Post ID | Meta Key                     | Meta Value
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12      | _sku, _price, _regular_price | 18945236, 1569.36, 1496.20

如果可以,请告诉我解决方案。

如果有任何更好的方法也欢迎。

谢谢

SELECT posts.ID, 
       GROUP_CONCAT(postmeta.meta_key ORDER BY posts.ID) meta_keys, 
       GROUP_CONCAT(postmeta.meta_value ORDER BY posts.ID) meta_values 
FROM wp_u8gwgg_posts as posts
INNER JOIN wp_u8gwgg_postmeta as postmeta on posts.ID = postmeta.post_id
WHERE posts.post_type = 'product' 
  AND posts.post_status = 'publish'
GROUP BY posts.ID
ORDER BY posts.ID