php - 如何检索同兴趣用户的状态 Mysql查询问题

标签 php mysql sql sql-server sql-server-2008

我正在学习 MYsql 和 php。现在在 mysql 中遇到了这个奇怪的问题。我有两张 table soc_users_interestsoc_status。请参见下面的表结构。

----------                -----------
soc_status                soc_users_interest
----------                ------------
status_ID                 soc_interest_id (Auto increment)
status                    userID
userID                    Interest

我正在尝试列出与用户(使用该应用程序的用户)具有相同兴趣的用户的所有状态。我进行了查询,但没有返回正确的结果。这是我写的查询,它不起作用。

 SELECT soc_status.statusID, soc_status.status FROM soc_status
WHERE soc_status.userID =

      (SELECT  
  soc_users_interest.userID as firstUser , 
  soc_users_interest.interest as firstUserInterest , 

  secondUser.userID as secondUser, 
  secondUser.interest as secondUserInterest 

 FROM soc_users_interest JOIN
  soc_users_interest secondUser 
     ON soc_users_interest.interest = soc_users_interest.interest) WHERE soc_users_interests.userID = "23445";

I am getting this error -> `[2016-07-09 20:53:26] [21000][1241] Operand should contain 1 column(s)`

如何列出与用户(使用该应用程序的用户)具有相同兴趣的用户的所有状态?这个问题有什么解决办法吗?感谢您的帮助;)

最佳答案

SELECT soc2.userID, soc2.status, int.interest  FROM soc_status soc1
join soc_status soc2 on soc1.user_id=soc2.user_id and soc1.user_id="23445"
join soc_users_interest int on soc1.user_id=int.user_id

关于php - 如何检索同兴趣用户的状态 Mysql查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38287578/

相关文章:

mysql - 一个项目总是放在最后的 SQL 查询

mysql - 奇怪的 SQL 代码 : Why do they use a subquery instead of join?

php - Highchart - 显示 JSON 数据 - MYSQL/PHP

php - 检查数组中的值并创建 php if 语句

php - mysql 中的总页面浏览量

mysql - 访问静态页面时不要连接mysql服务器

sql - 如何仅从 postgresQL 中的日期获取日期/月份部分

mysql - ELSE '60+' 在 CASE 语句中不工作,但 ELSE 'Others' 工作

从 MySQL 进行 PHP 查询而不重复

php - Wordpress Static 使用 HTTP 而不是 HTTPS