mysql version: 5.7.*
數(shù)據(jù)
students
| id | name |
|---|---|
| 1001 | tom |
| 1002 | jack |
| 1003 | jason |
results
| student_id | score | score_name |
|---|---|---|
| 1001 | 60 | Math |
| 1002 | 70 | History |
| 1005 | 80 | History |
內(nèi)鏈接
select * from student as s join results as r on s.id=r.student_id where r.score>60;
select * from 表1 join 表2 on 表1.id=表2.id where 其他條件
左鏈接
left join左邊的表中的數(shù)據(jù)全部查詢出來,右邊的的表中符合條件的查詢出來
select * from student as s left join retults as r on s.id=r.student_id where r.score>60
select * from 表1 right join 表2 on 表1.id=表2.id where 其他條件
右鏈接
rigit join右邊的表中的數(shù)據(jù)全部查詢出來,左邊的的表中符合條件的查詢出來
select * from student as s right join retults as r on s.id=r.student_id where r.score>60
select * from 表1 left join 表2 on 表1.id=表2.id where 其他條件