SQL study Note 6 union result set usage

Source: Internet
Author: User

Union result set
Create temporary data table
Copy codeThe Code is as follows:
Create table T_TempEmployee (FIdCardNumber VARCHAR (20), FName VARCHAR (20), FAge int, primary key (FIdCardNumber ));
Insert into T_TempEmployee (FIdCardNumber, FName, FAge) VALUES ('20140901', 'sarani ', 33 );
Insert into T_TempEmployee (FIdCardNumber, FName, FAge) VALUES ('20140901', 'Tom ', 26 );
Insert into T_TempEmployee (FIdCardNumber, FName, FAge) VALUES ('20170101', 'alaha', 38 );
Insert into T_TempEmployee (FIdCardNumber, FName, FAge) VALUES ('20140901', 'tina ', 26 );
Insert into T_TempEmployee (FIdCardNumber, FName, FAge) VALUES ('20140901', 'konkaya', 29 );
Insert into T_TempEmployee (FIdCardNumber, FName, FAge) VALUES ('000000', 'fotifa ', 46 );


Union
Copy codeThe Code is as follows:
Select FNumber, FAge from T_Employee
Union
Select FIdCardNumber, FAge from T_TempEmployee


The number and type of queries on and off the union must be consistent.
Copy codeThe Code is as follows:
Select FNumber, FAge, FDepartment from T_Employee
Union
Select FIdCardNumber, FAge, 'temporary employee, no departments' from T_TempEmployee


Union removes duplicate data by default. If he is not removed, union all is used.
Copy codeThe Code is as follows:
Select FName from T_Employee
Union all
Select FName from T_TempEmployee

Related Article

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.