很基礎的SQL 內串連與外串連,基礎sql串連

來源:互聯網
上載者:User

很基礎的SQL 內串連與外串連,基礎sql串連

一直以來有些問題會很鬱悶,如:為什麼會同時存在左右串連這個東西,假如外鍵為空白,那麼建立語句時就會存在外鍵約束失敗的問題。

後來仔細研究了下,內串連、外串連(左串連、右串連)是建立在不存在主外鍵約束關係的表之中。

其實都是很基礎的東西了,我之前沒搞明白,今天花時間整理了下。

首先select * from t_class


然後select * from t_student



1,內串連

內串連:利用內串連可擷取兩表的公用部分的記錄,即圖3的記錄集C 語句如下:Select * from t_class JOIN t_student ON t_class.id=t_student.belongClass_id 運行結果如4所示:它與select * from t_student,t_class WHERE t_class.id=t_student.belongClass_id;的運行結果是一樣的。

2.外串連分為左串連和右串連

左串連(公用部分加t_student的記錄)

右串連(公用部分加t_class的記錄)


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.