我有两个表,用户表和关系表。Users表包含以下列:
id, name,password,username,email,avatar,followersCount,followingCount,tweetCount.并且关系表格具有以下列:
id, followingId, followerId我应该如何创建SQL查询来提取具有特定Id的用户,并从该用户所关注的关系中查找id?所以换句话说,找到用户关注的人
我已经走了这么久
SELECT *
FROM public."Users" JOIN
public."Relationships"
ON (public."Users".id = public."Relationships".id) 发布于 2020-11-11 19:36:14
如果我没理解错的话,你想:
SELECT u.*
FROM public."Relationships" r JOIN
public."Users" u
ON u.id = r.followerId
WHERE r.followingId = ?;?是您关心的用户的参数占位符。这将返回该用户的所有关注者。
发布于 2020-11-11 19:46:37
你是说这个查询吗?
SELECT public."Users".*
FROM public."Users"
JOIN public."Relationships"
ON public."Users".id = public."Relationships".followingId
AND public."Relationships".followerId = a user ID我不太清楚followerId和followingId的含义,但如果不是您想要的,您可以在查询中更改它们。
https://stackoverflow.com/questions/64785598
复制相似问题