MySql 的外连接

MySql 的外连接
数据库教科书上的外连接实例:
SELECT *
FROM Student,SC
WHERE Student.Sno=SC.Sno(*);

在MySql中不可行,说某些数据库中用'+'而不是'*',括号中换用'+'之后仍然无效。Google后解决,记下笔记。

左外连接: 以Student表(Student表行数较多)为主体列出,若SC表(比Student表行数少)无对应项,则为空值,故左连接NULL应该出现右边。
select * from Student left outer join SC on Student.Sno=SC.Sno;


右外连接:以SC表为主体列出,NULL出现在左边。
select * from Student right outer join SC on Student.Sno=SC.Sno;

你可能感兴趣的:(MySql 的外连接)