我正在尝试编写SQL语句,但我遇到了麻烦。我有以下表格
备注
person_user VARCHAR
message VARCHAR
time DATETIME
id INT (primary Key)
人
name (primary key)
address VARCHAR
telephone INT
Associated_With
person_associating VARCHAR
person_associating_with VARCHAR
我需要显示注释,只需要person_associating_with
表中Associated_With
写的注释。
这是我现在的尝试:
SELECT *
FROM Notes
INNER JOIN Notes.person_user ON Notes.id AS associatedMessages
INNER JOIN Associated_With On associatedMessages
WHERE
Person.name = person_associating
ORDER BY
time DESC;
目前我无法获得所有可能的结果
答案 0 :(得分:1)
我假设您正在寻找以下内容:
SELECT *
FROM Notes AS ABB2
JOIN Associated_With AS ABB1 ON
ABB1.person_associating_with = ABB2.person_user
ORDER BY time DESC
在原始查询中,您尝试连接具有ON条件和WHERE条件的表。尽管可以这样做,但最好使用其中一种来保持一致性。
答案 1 :(得分:0)
如果我理解正确,你可能不是在寻找连接而是IN语句:
SELECT *
FROM Notes
WHERE person_user IN
(SELECT person_associating_with
FROM Associated_With);