Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL如何从引用的表中检索值?_Mysql - Fatal编程技术网

MySQL如何从引用的表中检索值?

MySQL如何从引用的表中检索值?,mysql,Mysql,我正在尝试学习各种表中字段之间的引用关系,但我很难理解以下内容: 如果我有两张桌子: 1) 一种是针对有姓名、年龄、id、gpa和年级的学生 2) 一种是教师点名,上面有班级名称、组号和上课学生的ID 如何编写类似于以下伪代码的查询: SELECT classname and sectionnumber WHERE the students in the class at least junior? 如何使用一个表中的字段引用另一个被引用表中的字段值 select a.cla

我正在尝试学习各种表中字段之间的引用关系,但我很难理解以下内容:

如果我有两张桌子:

1) 一种是针对有姓名、年龄、id、gpa和年级的学生

2) 一种是教师点名,上面有班级名称、组号和上课学生的ID

如何编写类似于以下伪代码的查询:

         SELECT classname and sectionnumber WHERE the students in the class at least junior?
如何使用一个表中的字段引用另一个被引用表中的字段值

select a.classname, a.sectionNo
   from ClassRosert a 
   inner join Student b using(studentId)
   where b.class = 'junior';
或者在那种情况下你可以这样做

select a.classname, a.sectionNo
   from ClassRosert a, Student b 
   where a.studentId = b.studentId
     and b.class = 'junior';
但我会推荐第一个,因为更清楚的是,你们正在加入谈判桌


注意,在第一种情况下,我使用了
using
关键字,因为映射值在两个表中具有相同的名称(studentId)。但是,如果在student表中它只被称为ID或任何其他名称,则联接将是
内部联接student b on a.studentid=b.ID

在选择后添加distinct关键字以避免重复<代码>选择不同的