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%' + '%')
精彩评论