【发布时间】:2016-11-12 06:10:56
【问题描述】:
我正在学习 MYsql 和 php。现在在mysql中遇到了这个奇怪的问题。我有两张桌子
soc_users_interest 和 soc_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)`
如何列出与用户(使用应用程序的用户)具有相同兴趣的用户的所有状态?这个问题的任何解决方案?感谢您的帮助;)
【问题讨论】:
-
“它不起作用”根本没有给我们任何有用的信息。如果它工作正常,你就不会在这里问问题。什么是预期的输出?电流输出是多少?有错误信息吗?
-
我更新了问题。 @乔斯林
-
试试
soc_status.userID in( )而不是soc_status.userID = -
相同的错误操作数应包含 1 列 @starshine531
-
好的,发生这种情况的原因是您在子查询中选择了 4 个不同的字段。它只需是此查询当前结构的一种方式。
标签: php mysql sql sql-server sql-server-2008