INNER JOIN 关键字语法
SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name
题目:
请编写 SQL 语句,将课程表 courses 和教师表 teachers 进行内连接,查询 “Eastern Heretic” 老师所教的所有课程的课程名和课程编号 , 且结果列名分别以课程编号 id 、课程名称 course_name 和教师姓名 teacher_name 显示。
错误写法:
SELECT courses.id,courses.courses_name,teachers.teacher_name
FROM teachers
INNER JOIN courses
ON courses.id = teachers.id where teachers.teacher_name = “Eastern Heretic"
正确写法:
SELECT c.id,c.name as course_name,t.name as teacher_name
FROM teachers t
inner join courses c on c.teacher_id=t.id
WHERE t.name='Eastern Heretic'