左串連/右串連 執行個體

來源:互聯網
上載者:User

有兩個表。

table1:

id name password
1 aaa a
2 bbb b
3 ccc c
table2:

id power null
1 111000 null
2 111 null

左串連sql語句:select table1.id,table1.name,table2.power from table1 left join table2 on table1.id = table2.id

查詢結果:

id name power
1 aaa 111
2 bbb 111000
3 ccc null
右串連sql語句:select table1.id,table1.name,table2.power from table1 right join table2 on table1.id = table2.id

查詢結果:

id name power
1 aaa 111
2 bbb 111000

總結:

1、左/右串連查詢實際上是指定以哪個表的資料為準。
2、左串連是只要左邊的表中有記錄,資料就能檢索出來,而右邊表中的記錄必須在
3、左邊表中有記錄才能檢索出來;右串連同理。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.