MySQL从多个表中选择
SELECT * FROM dog WHERE (SELECT calluser FROM jos_users WHERE `user_id`='".$cid."')=Subcode
$cid
是jos_users
中的标识符,它告诉我们要获取哪些用户的数据我
要获取的数据在“dog”内,calluser是标识符在两者之间(它告诉我们谁的狗是谁),
我需要能够仅调用与相关用户相关的狗,但它也必须在一个查询中执行。有人可以帮忙吗?非常感谢。
SELECT * FROM dog WHERE (SELECT calluser FROM jos_users WHERE `user_id`='".$cid."')=Subcode
$cid
is the identifier in jos_users
, which tells us which users we're fetching data about
The data I want to fetch is within "dog", and calluser is the identifier between the two (which tells us who's dogs are who's)
I need to be able to call only the dogs relevant to the user in question, but it also has to be performed in one query. Can anyone help? Much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用联接。
阅读本教程: http://www.tizag.com/mysqlTutorial/
您的查询应该类似于这:
You need to use joins.
Read this tutorial: http://www.tizag.com/mysqlTutorial/
Your query should look something like this:
如果我的理解正确(并且dog表中的id列链接到jos_user表中的calluser列),则查询应该是
如果不是,请更详细地解释您的数据结构(可能是小ER图)。
If I got you right (and the id column in the dog-table links to the calluser column in the jos_user-table) the query should be
If not please explain your data structure in more detail (maybee small ER diagram).