SQL Learning Combination query (UNION)

Source: Internet
Author: User

1. Most SQL queries contain only a single SELECT statement that returns data from one or more tables, but SQL also allows multiple queries (multiple SELECT statements) to be executed and the result returned as a query result set. These combined queries are commonly referred to as and or compound queries.

There are two main scenarios in which you need to use a combination query:

(1) Return structure data from a different table in a query

(2) Execute multiple queries against one, return data by one query

2. Use Union

Using Union is simple, all you have to do is give each SELECT statement, and then add the Union keyword between each SELECT statement so that the selected result set can be combined into a single result set and returned. The code is as follows:

SQL Learning Combination query (UNION)

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.