简体   繁体   English

如何从单个子查询中获取2列值

[英]How to get 2 column values from single subquery

Here is my query: I want to get the user values which is stored in user table and comments which is stored in comments table. 这是我的查询:我想获取存储在用户表中的用户值和存储在注释表中的注释。
The user_id is the id of the user which i fetch from comments table. user_id是我从评论表中获取的用户的ID。
How to get both comments with respective users how to do that with single query or there is any good and best way to do that? 如何获得与各自用户的两个评论,如何通过单个查询做到这一点,或者有什么好的和最好的方式做到这一点?

mysql_query("select profile_pic,firstname,lastname,username,comment from user join  comments where user_no IN (select user_id,comment from comments where   question_id='".$_POST['get_comments']."') ");

Try 尝试

SELECT profile_pic,firstname,lastname,username,comment 
FROM `user`
INNER JOIN comments ON `user`.user_no = comments.user_id
WHERE comments.question_id='".$_POST['get_comments']."'

i think the join condition you didn't specify and also you didn't specify what type of join you required try this code. 我认为您未指定的联接条件,也未指定所需的联接类型,请尝试此代码。

mysql_query("select profile_pic,firstname,lastname,username,comment from user left join  comments on user.columnname=comments.columnname where user_no IN (select user_id,comment from comments where   question_id='".$_POST['get_comments']."') ");

The column name specifies on which column you want to join to tables.for reference please read this 列名指定要连接到表的列。有关参考,请阅读此内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM