名词:
内连接:自然连接,只有两个相匹配的行才能在结果集中显示
外连接:左外连接、右连接、全外连接
内连接,只显示满足where后条件的列 select a.*,b.* from a inner join b on a.id=b.parent_id
左外连接,select a.*,b.* from a left join b on a.id=b.parent_id 左列为主,右表为副表。
右外连接, select a.*,b.* from a right join b on a.id=b.parent_id 左列为副表,右表为主表
全外连接,select a.*,b.* from a full join b on a.id=b.parent_id 返回左表和右表的全部值 ,当某表在一另外一表无匹配值 ,则为空
注意:mysql不支持Full join,
实践操作:1、内连接 SELECT student.name,teacher.high FROM student INNER JOIN teacher ON student.id=teacher.id;
2、左外连接 SELECT student.name,teacher.high FROM student LEFT JOIN teacher ON student.id=teacher.id;
3、右外连接 SELECT student.name,teacher.high FROM student RIGHT JOIN teacher ON student.id=teacher.id;
操作过程中碰到的问题:出现1066号错误 ,刚开始为是不能显示相同的列,实际是语句中缺少 on