开发者

Wordpress SQL Questions

I have a problem, I would like to know how to combine this query to perform a search

SELECT user_id
FROM wp_usermeta
WHERE meta_key =  'g_State'
AND meta_value LIKE  '%Pahang%'

with

SELECT user_id
FROM wp_usermeta
WHERE meta_key =  'g_Categories'
AND meta_value LIKE  '%cat001%'
AND meta_value LIKE  '%cat002%'

is it possible to do it without changing the stru开发者_开发百科cture of the tables?


SELECT user_id 
FROM wp_usermeta 
WHERE (meta_key = 'g_State' AND meta_value LIKE '%Pahang%')
   OR (meta_key = 'g_Categories' AND 
       meta_value LIKE '%cat001%' AND meta_value LIKE '%cat002%')


If you want to combine the results, rewrite your where clause:

SELECT user_id FROM wp_usermeta WHERE (meta_key = 'g_State' AND meta_value LIKE '%Pahang%') OR (meta_key = 'g_Categories' AND meta_value LIKE '%cat001%' AND meta_value LIKE '%cat002%')


Try this.

SELECT user_id
FROM wp_usermeta
WHERE (meta_key =  'g_State'
AND meta_value LIKE  'Pahang' + '%')
OR
(meta_key =  'g_Categories'
AND meta_value LIKE  'cat001' + '%'
AND meta_value LIKE  'cat002%' + '%')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜