select users_group.uid, users.username, users.password from user_group inner join users on user_group.uid=users.id where gid in (select gid from user_group where uid=1);
你的方案应该修改为:
1>如果一个用户可以属于一个以上的组:
select * from users where id in (select uid from user_group where gid in (select gid from user_group where uid = 1));
或者:
2>如果一个用户只能属于一个组:
select * from users where id in (select uid from user_group where gid = (select gid from user_group where uid = 1));