简体   繁体   English

INNER JOIN查询三个表

[英]INNER JOIN Query three tables

I have a three table setup in my database: members, clases, classregistration. 我的数据库中有一个三表设置:成员,类,类注册。 The class registration table has m_id and c_id columns that store the member id and class id. 类注册表具有m_id和c_id列,用于存储成员ID和类ID。 For example if the same member registers with more classes it will be rows of same m_id with different c_id. 例如,如果同一成员注册更多类,则它将是具有相同c_id的相同m_id的行。 I am trying to view all members that are with a particular class and I have this query but it doesn't return anything. 我正在尝试查看具有特定类的所有成员,并且我有此查询,但它不返回任何内容。 Any suggestions what is wrong in my query? 有什么建议我的查询有什么问题吗? Thanks 谢谢

SELECT members.member_first_name, classregistration.c_id 
FROM classregistration INNER JOIN clases
ON classregistration.c_id = clases.class_id
WHERE classregistration.c_id = 1

You can give this a try: 您可以尝试一下:

SELECT m.member_first_name, cr.c_id 
FROM classregistration cr
  INNER JOIN clases c ON cr.c_id = c.class_id
  INNER JOIN members m ON m.member_id = cr.m_id
WHERE cr.c_id = 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM