Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL,使用2个表获取信息_Mysql - Fatal编程技术网

MySQL,使用2个表获取信息

MySQL,使用2个表获取信息,mysql,Mysql,有两个表:wp_users和wp_usermeta wp_users表的结构如下: id | email --------------- 1 | b@foo.com 2 | k@bah.com id | user_id | meta_key | meta_value --------------------------------------------------- 1 | 1 | firstname | bob 2

有两个表:wp_users和wp_usermeta

wp_users表的结构如下:

id | email
---------------
1  | b@foo.com
2  | k@bah.com
id | user_id | meta_key                | meta_value
---------------------------------------------------
1  | 1       | firstname               | bob
2  | 1       | lastname                | smith
3  | 1       | app_prefferedcategories | {"blog_id":"5"},{"blog_id":"22"}
4  | 2       | firstname               | jan
5  | 2       | lastname                | jones
6  | 2       | app_prefferedcategories | {"blog_id":"1"},{"blog_id":"7"}
wp_usermeta表的结构如下:

id | email
---------------
1  | b@foo.com
2  | k@bah.com
id | user_id | meta_key                | meta_value
---------------------------------------------------
1  | 1       | firstname               | bob
2  | 1       | lastname                | smith
3  | 1       | app_prefferedcategories | {"blog_id":"5"},{"blog_id":"22"}
4  | 2       | firstname               | jan
5  | 2       | lastname                | jones
6  | 2       | app_prefferedcategories | {"blog_id":"1"},{"blog_id":"7"}
我试图实现的是从meta_key app_preferedcategories中meta_值为{“blog_id”:“5”)的用户那里获取所有电子邮件地址。 我知道如何一次查询一个表,但我很难加入它们。 有人能照一下这个吗

提前谢谢

select u.email
from wp_usermeta m
inner join wp_users u on u.id = m.user_id
where meta_key = 'app_prefferedcategories'
and find_in_set('{"blog_id":"5"}', meta_value) > 0