Two tables:
1Mysql> Select * fromstudent;2 +----+------+------+3 |Id|Name|Age|4 +----+------+------+5 | 1 |Xiao Wang| - |6 | 2 |Little Red| - |7 | 3 |Xiao ming| - |8 | 4 |Xiao Li| A |9 | 5 |Jack bauer| - |Ten +----+------+------+ One 5Rowsinch Set(0.00Sec
1Mysql> Select * fromMark;2 +----+------+-----------+3 |Id|Mark|StudentID|4 +----+------+-----------+5 | 1 | A | 2 |6 | 2 | $ | 2 |7 | 3 | - | 3 |8 +----+------+-----------+9 3Rowsinch Set(0.00Sec
One, inner connection (inner join)
1Mysql> SelectS.name,m.mark fromStudent S,mark mwhereS.id=M.studentid;2 +------+------+3 |Name|Mark|4 +------+------+5 |Little Red| A |6 |Little Red| $ |7 |Xiao ming| - |8 +------+------+9 3Rowsinch Set(0.07sec)TenMysql> SelectS.name,m.mark fromStudent SInner JoinMark M onS.id=M.studentid; One +------+------+ A |Name|Mark| - +------+------+ - |Little Red| A | the |Little Red| $ | - |Xiao ming| - | - +------+------+ - 3Rowsinch Set(0.06Sec
Second, left join (left join)
1Mysql> SelectS.name,m.mark fromStudent S Left JoinMark M onS.id=M.studentid;2 +------+------+3 |Name|Mark|4 +------+------+5 |Little Red| A |6 |Little Red| $ |7 |Xiao ming| - |8 |Xiao Wang| NULL |9 |Xiao Li| NULL |Ten |Jack bauer| NULL | One +------+------+ A 6Rowsinch Set(0.07Sec
Third, right Join
1Mysql> SelectS.name,m.mark fromStudent S Right JoinMark M onS.id=M.studentid;2 +------+------+3 |Name|Mark|4 +------+------+5 |Little Red| A |6 |Little Red| $ |7 |Xiao ming| - |8 +------+------+9 3Rowsinch Set(0.00Sec
SQL table Connection Query