我有很多用于消息传递系统的表。但我无法向mysql发送查询。
SELECT
messages_list.IDUSER,
messages_list.IDPAGE,
messages_list.IDUSER,
messages_list.v_readed,
messages_list.IDUSER,
messages_texts.v_text,
messages_texts.v_time,
messages_subjects.v_title,
user_photos.v_photoURL,
user.v_sex,
(SELECT IDPHOTO FROM user WHERE messages_list.IDUSER)
FROM
messages_texts,
user
INNER JOIN user_photos ON user_photos.ID=user.IDPHOTO AND user_photos.v_active='1'
INNER JOIN messages_list ON messages_list.IDUSER=717306 AND messages_list.v_active='1'
INNER JOIN messages_subjects ON messages_list.IDSUBJECT=messages_subjects.ID
INNER JOIN messages_users ON messages_users.IDSUBJECT=messages_subjects.ID AND messages_users.IDUSER=user.ID
WHERE
messages_users.IDUSER<>717306
GROUP BY messages_subjects.ID
ORDER BY messages_list.ID
)\n: (Subquery returns more than 1 row)
问题在哪里?
答案 0 :(得分:2)
问题是这个子查询:
(SELECT IDPHOTO FROM user WHERE messages_list.IDUSER)
它嵌套在select
语句中,因此它应该只返回一个值。 where
子句仅包含IDUSER
值。只要不是0
(假设该字段是整数),这将返回“true”。所以,它基本上会返回所有用户。
据推测,您想要特定用户的IDPHOTO
:
(SELECT IDPHOTO FROM user WHERE messages_list.IDUSER = user.ID)
答案 1 :(得分:0)
相关子查询不能返回多行。此查询:
SELECT IDPHOTO FROM user WHERE messages_list.IDUSER
返回不能执行的多行。您只需使用LIMIT
子句将其限制为一行:
SELECT IDPHOTO FROM user WHERE messages_list.IDUSER LIMIT 1
或者使用特定的密钥:
SELECT IDPHOTO FROM user WHERE messages_list.IDUSER WHERE id=1