A small application of full join

Source: Internet
Author: User
Code
Create   Table Table1 (PID Int , Product Varchar ( 20 ), Inputnum Int )
Go
Insert   Into Table1 Select   1 , ' A ' , 20
Insert   Into Table1 Select   3 , ' C ' , 10
Insert   Into Table1 Select   5 , ' E ' , 30
Create   Table Table2 (PID Int , Product Varchar ( 20 ), Outputnum Int )
Go
Insert   Into Table 2 Select   1 , ' A ' , 30
Insert   Into Table 2 Select   2 , ' B ' , 8
Insert   Into Table 2 Select   4 , ' D ' , 15  
Go
Select   Isnull (T1.pid, t2.pid) As PID, Isnull (T1.product, t2.product) As Product, Isnull (Inputnum, 0 ) As Inputnum, Isnull (Outputnum, 0 ) As Outputnum
From Table1 T1 Full   Join Table2 T2
On T1.pid = T2.pid
Order   By PID
Go
Drop   Table Table1, Table2
Go

/* Result
PID product inputnum outputnum
-----------------------------------------------------
1 A 20 30
2 B 0 8
3 C 10 0
4 D 0 15
5 E 30 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.