从他们属于MySQL的所有组中选择用户

时间:2015-01-12 08:31:44

标签: mysql sql

我将从他们所属的群组中选择所有用户。

数据库就是这个。

Classroom Table // This is the GROUP .. or Classroom Group
>classroom_id (pk)
>classroom_name
>classroom_description
>instructor_id


CLassroom Members Table
>classroom_id (fk)
>account_id (fk)

User Table
>account_id (pk)
>account_name

..我已经测试了一些..但是,请你给我一些建议或sql逻辑

2 个答案:

答案 0 :(得分:0)

Select * from User as u

Join Classroom Members as cm 
on u.account_id=cm.account_id 

join Classroom as c 
on cm.classroom_id=c.classroom_id

order by c.classroom_id desc

答案 1 :(得分:0)

select a.account_name,c.classroom_name,c.classroom_description
from  CLassroom_Members_Table b
join User_Table a
on b.account_id=a.account_id 
join Classroom_Table c
on b.classroom_id= c.classroom_id 
Where instructor_id=1

这提供了教室里学生的详细信息,其中instructor_id = 1

这对你有帮助....

感谢。

如果有帮助,请标记为答案或投票