SQL from getting started to basic –08 Union, union all, and cases

Source: Internet
Author: User
I. Joint result set

1. Simple result set Union:

Select Fnumber,fname,fage from T_employee Union select Fidcardnumber,fname,fage from T_employee

2. Basic principle: Each result set must have the same number of columns: the columns of each result set must be type-compatible.

3. Select Fnumber,fname,fdepartment from T_employee Union select Fidcardnumber,fname,fage, ' temp, no department ' from T_employee

Second, Union all

1. Select Fname,fage from T_employee Union Select fname,fage from T_tempemployee.

Union merges two query result sets and merges the rows of data that are completely duplicated into one.

2. Select FName from T_employee UNION ALL Select FName from T_tempemployee.

Union is inefficient because it is being scanned for duplicate values, so if you are not sure that you want to merge duplicate rows, use UNION ALL.

Iii. Case 1

Iv. Case Two

SQL from getting started to basic –08 Union, union all, and cases

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.