我有一个问题是创建一个SQL查询请求。 我有一个工作查询,以获取类别和自定义帖子类型和meta_key地图坐标'在我的user_id上的wp_usermeta表中。 我尝试完成的是扩展查询,我还从我的wp_usermeta表中使用meta_key' some_value'获得另一个meta_value。 所以我需要搜索两个meta_keys值(mapcoordinates,somevalue)而不是一个(mapcoordinates),参见工作示例 也许有人可以帮助我
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID, wp_usermeta.meta_value AS user_map_coord, wp_usermeta.user_id
FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_usermeta ON ( wp_posts.post_author = wp_usermeta.user_id )
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (5,6))
AND wp_posts.post_type = 'ouder_type'
AND wp_usermeta.meta_key= 'mapcoordinates'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date
以上查询正在运行。 我喜欢用这样的东西扩展它。
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID, wp_usermeta.meta_value AS user_map_coord, wp_usermeta.user_id
FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_usermeta ON ( wp_posts.post_author = wp_usermeta.user_id )
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN ( 5,6))
AND wp_posts.post_type = 'ouder_type'
AND wp_usermeta.meta_key= 'mapcoordinates'
// this line added not working i get only one result , expecting 2 results
AND wp_usermeta.meta_key= 'somevalue'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date
答案 0 :(得分:0)
你有wp_usermeta.meta_key同时等于两个不同的东西,所以可能不应该得到任何结果。我想你所追求的更多的是:
AND wp_usermeta.meta_key IN('mapcoordinates','somevalue')