开发者

MySQL meta search using distinct

I have a sql search like below:

select distinct user_id from wp_usermeta where ( meta_key='postcode' and meta_value= '3000') or ( meta_key='state' and meta_value= 'vic') or ( meta_key='maternitybg' and meta_value= 'No')

My question is how do I change the query so it searches meta_value 3000, vic and No for user_id? All rows have user开发者_开发技巧_id attached to it so this is why I'm using distinct function as it clears duplicates. The problem at the moment is it gets all users with meta_value of No and this is not what I want as I would like to filter by postcode and state aswell.

Any ideas?


SELECT user_id FROM wp_usermeta
WHERE ( meta_key='postcode' AND meta_value= '3000') OR
      ( meta_key='state' AND meta_value= 'vic') OR
      ( meta_key='maternitybg' AND meta_value= 'No' )
GROUP BY user_id
HAVING COUNT(DISTINCT meta_key) = 3
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜