我有2个查询如下,
A SELECT DISTINCT meta_value, meta_id FROM `wp_postmeta` WHERE `meta_key`='destination';
B SELECT ID FROM wp_posts WHERE post_status = 'publish';
我想要的是这样的,
SELECT meta_value FROM A WHERE A.meta_id = B.ID;
SELECT DISTINCT
meta_value
FROM `wp_postmeta` wpm,
wp_posts wp
WHERE wp.ID = wpm.meta_id
AND wpm.`meta_key` = 'destination'
AND wp.post_status = 'publish';
试试这个
SELECT A.meta_value, A.meta_id
FROM `wp_postmeta` A
INNER JOIN wp_posts B
ON meta_id = id
WHERE A.`meta_key`= 'destination'
AND B.post_status = 'publish'
GROUP BY A.meta_value