LEFT OUTER JOIN 使用實況

來源:互聯網
上載者:User
 

LEFT OUTER JOIN 使用實況

定義就不用說了吧!

測試資料 test_table

create table test_table
(u_id int,u_name varchar(20))
insert test_table select 1,'a1'
union all select 2,'b2'
union all select 3,'c3';

測試資料 test_table_link

create table test_table_link
(u_id int,u_other varchar(50))
insert test_table_link select 1,'each month'
union all select 1,'each day'
union all select 1,'each year'
union all select 55,'each day'
union all select 55,'each year'
union all select 3,'each day'
union all select 3,'each year'
union all select 88,'each day'
union all select 88,'each month';

結果

select a.u_id,a.u_name,b.u_other
from test_table a LEFT OUTER JOIN test_table_link b
ON  a.u_id=b.u_id;

測試環境為sql server 2005

原本以為只是顯示test_table中的每3條記錄,實際上不是這樣的(為什麼多了記錄了呢?),只要第一個表(test_table)中有,而第二個表與之相關聯得上的都會顯示的,但是一定要在第一個表(test_table)中存在,如第二個表(test_table_link)中的uid為55,88的不會出現,若第二個表沒有找到與第一個表相匹配的那當然為null了!right outer join就與之相反了.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.