使用 MySQL 连接三个表
要连接三个表并以特定格式显示结果,请按照以下步骤操作:
加入学生、课程和 Bridge 的步骤表:
从连接表的 ANSI 标准 SQL 语法开始:
SELECT s.name AS Student, c.name AS Course FROM student s INNER JOIN bridge b ON s.id = b.sid INNER JOIN course c ON b.cid = c.id
此查询将正确连接表格并显示所需的结果:
| Student | Course | |---|---| | ahmed | physic | | ahmed | maths | | ahmed | computer | | ahmed | chemistry | | ali | physic | | ali | maths | | john | computer | | john | chemistry | | king | physic | | king | maths |
加入员工和管理表的步骤:
使用以下查询加入员工和管理表:
SELECT e1.name AS Manager, e2.name AS Staff FROM employee e1 INNER JOIN manage m ON e1.id = m.mid INNER JOIN employee e2 ON m.eid = e2.id
此查询将返回所需的结果:
| Manager | Staff | |---|---| | ali | king | | ali | mak | | mak | sam | | sam | jon |
以上是如何在MySQL中连接三个表以显示特定结果?的详细内容。更多信息请关注PHP中文网其他相关文章!