如何从3个MySQL表中选择Name,Second Name和Name_Chairrr?

时间:2016-09-14 18:07:05

标签: mysql sql database relationship

这是DB的方案。如何从MySQL的3个表中选择Name,Second Name和Name_Chairrr ????

enter image description here

SELECT p.Name, p.Second_Name, c.Name_CHAIRRR 
FROM Professors p  
JOIN pchairs pc ON pc.ID_Professor = p.ID_professor 
JOIN Chairs c ON c.ID_chair = pc.ID_Chair

2 个答案:

答案 0 :(得分:0)

您必须将表连接在一起并使用别名。试试这个

SELECT p.Name, p.Second_Name, c.Name_CHAIRRR
FROM Professors p
JOIN pchairs pc ON pc.ID_Professor = p.ID_professor
JOIN Chairs c ON c.ID_chair = pc.ID_Chair

答案 1 :(得分:0)

我认为你正在寻找这个

select
    p.name,
    p.second_name,
    c.name_chairrr
from
    professors p
inner join
    pchairs pc
on
    p.id_professor=pc.id_professor
inner join
    chairs c
on
    pc.id_chair=c.id_chair