下面的查询不返回任何值,name1
因为它没有wp_postmeta.meta_key = 'wpcf-phone'
. 我LEFT OUTER JOIN
认为它会返回结果,name1
因为它有值,wp_posts
但它只是返回值,name2
它确实有一个wp_postmeta.meta_key = 'wpcf-phone'
.
SELECT
wp_posts.ID,
wp_posts.post_content,
wp_posts.post_title,
wp_postmeta.meta_value AS phone
FROM
wp_posts
LEFT OUTER JOIN wp_postmeta wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
WHERE
wp_posts.post_type = 'solicitors' AND
wp_posts.post_status = 'publish' AND
wp_postmeta.meta_key = 'wpcf-phone' AND
(wp_posts.post_title LIKE '%name1%' OR
wp_posts.post_title LIKE '%name2%')