表结构:
users: uid, name
friendships: uid1, uid2
game_membership: gid, uid
基本上我试图获取一个作为函数的查询gid
,并返回:
uid1, name1, uid2, name2
其中仅返回给定表uid
中的 's 。这是我到目前为止所得到的:game_membership
gid
SELECT
f.uid1 AS id1,
u1.name AS name1,
f.uid2 AS id2,
u2.name AS name2
FROM
friendships AS f
WHERE
u1.uid in (SELECT uid FROM game_membership WHERE gid = <GID>)
AND u2.uid in (SELECT uid FROM game_membership WHERE gid = <GID>)
JOIN users AS u1 ON f.uid1 = u1.uid
JOIN users AS u2 ON f.uid2 = u2.uid
我现在刚刚收到一个 MySQL 语法错误。谁能指出我正确的方向?我觉得也许我必须uid
在表中的 's上再做一个或两个 JOIN game_membership
,每个一个uid
?