从一个表中选取行,但 where 语句条件在另一表中
我有 2 个表,我必须使用 where =“这个值在其他表中”获取一个表的数据
users_info and users_frnds
users_info look like this
name image presently id
somename somimage studying 2
somename somimage studying 3
users_frnds table looks like this
userid friendid
1 2
1 3
$query = "SELECT * FROM users_info WHERE users_info.id =
users_frnds.friendid";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['name']. " - ". $row['image'];
echo "<br />";
,但它在这里似乎不起作用。我想立即将所有数据放入我的数组中。
它向我抛出这个错误:
Unknown column 'users_frnds.friendid' in 'where clause'
I have 2 tables, I have to get the data of one table using where = "this value in some other table"
users_info and users_frnds
users_info look like this
name image presently id
somename somimage studying 2
somename somimage studying 3
users_frnds table looks like this
userid friendid
1 2
1 3
$query = "SELECT * FROM users_info WHERE users_info.id =
users_frnds.friendid";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['name']. " - ". $row['image'];
echo "<br />";
but it does not seem to work here. I wanted to get all the data at once into my array.
It throws me this error:
Unknown column 'users_frnds.friendid' in 'where clause'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要联接,例如:
然后您将获得访问权限,尽量不要在 WHERE 子句中联接表,因为这可能会创建非常不可读的查询。
You will need to join, like:
Then you will get access, try never to join tables in the WHERE clause because that can create quite unreadable queries.