使用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中文網其他相關文章!