Joining three tables using MySQL

前端 未结 9 2267
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 10:40

I have three tables named

**Student Table**
-------------
id    name
-------------
1     ali
2     ahmed
3     john
4     king

**Course Table**
------------         


        
相关标签:
9条回答
  • 2020-11-22 11:12

    Use this:

    SELECT s.name AS Student, c.name AS Course 
    FROM student s 
      LEFT JOIN (bridge b CROSS JOIN course c) 
        ON (s.id = b.sid AND b.cid = c.id);
    
    0 讨论(0)
  • 2020-11-22 11:14

    Simply use:

    select s.name "Student", c.name "Course"
    from student s, bridge b, course c
    where b.sid = s.sid and b.cid = c.cid 
    
    0 讨论(0)
  • 2020-11-22 11:14

    For normalize form

    select e1.name as 'Manager', e2.name as 'Staff'
    from employee e1 
    left join manage m on m.mid = e1.id
    left join employee e2 on m.eid = e2.id
    
    0 讨论(0)
提交回复
热议问题