我试图使用MySQL连接子查询,子查询也有连接所以我面临问题,请善待,因为我不是没有尝试,我尽力解决但是得到语法错误这是因为相关名称为t1和t2
SELECT min(user_org.oid) as id, user_org_profiles.name from user_org
LEFT JOIN user_org_profiles ON (user_org.oid = user_org_profiles.oid) t1
INNER JOIN
(SELECT user_org_profiles.name, max(user_org.gid) as gid
FROM user_org LEFT JOIN user_org_profiles USING(oid)
WHERE user_org.gid IN (1,2]) AND active =1
group by name) t2 ON t1.name = t2.name AND t1.gid = t2.gid group by t1.name
纠正此错误
答案 0 :(得分:1)
修复了user_org_profiles
的别名为t1
加上IN
列表中的小错误的问题。这些错误与消息中报道的文字并不十分接近。
SELECT min(user_org.oid) as id, t1.name from user_org
LEFT JOIN user_org_profiles t1 ON (user_org.oid = t1.oid)
INNER JOIN
(SELECT user_org_profiles.name, max(user_org.gid) as gid
FROM user_org LEFT JOIN user_org_profiles USING(oid)
WHERE user_org.gid IN (1,2) AND active = 1
group by name) t2 ON t1.name = t2.name AND t1.gid = t2.gid group by t1.name