The purpose of the Union directive is to combine the results of two SQL statements. From this point of view, we have this feeling that union and join seem to be similar, because these two instructions can be retrieved from multiple tables. One limitation of the Union is that the columns generated by the two SQL statements need to be of the same type of data.Also,
The purpose of the Union directive is to combine the results of two SQL statements. From this point of view, we have this feeling that union and join seem to be similar, because these two instructions can be retrieved from multiple tables. One limitation of the Union is that the columns generated by the two SQL statements need to be of the same type of data.Also,
SQL UNION operatorThe UNION operator is used to combine the result set of two or more SELECT statements.Note that the SELECT statement inside the UNION must have the same number of columns. The column must also have a similar data type. Also, the order of the columns in each SELECT statement must be the same.SQL UNION
In the project, the region information for reference to this quote region is queried, and the information for this region and the queried reference quote region information are combined into a temporary table, which uses union or union all,
SQLCodeAs follows:
SQL 1
1 Create Type ty_areaandgoods As Table ( 2 Areaid Int , 3 Typeid Int 4 ) 5 Declare @ Dt Ty_areaandgoods; 6 Insert Into @
This evening, we found the difference between the two tables. Haha.
Union concatenates two tables and deletes their repeated items;
Union all does not delete the duplicate items of the two tables.
This is simple. But also record it. It is a small achievement.
Additional information:
In the database, union and Union
Union operator:
Combine the results of two or more queries into a single result set that contains all rows of all queries in the Union query. This is different from using join to combine columns in two tables.
The two basic rules for combining two query result sets using union are:
The columns and columns in all queries must be in the same order.
The data
This evening, we found two differences in the operation of two tables. Oh.
Union joins two tables and deletes their duplicates;
UNION ALL joins the two tables without deleting their duplicates.
This stuff is very simple. But also record a ha. It's a small harvest.
Supplementary information:
In the database, Union and
If we have a table student that contains the following fields and data:
Drop table student; Create Table student (ID int primary key, name nvarchar2 (50) not null, score number not null); insert into student values (1, 'Aaron ', 78); insert into student values (2, 'bill ', 76); insert into student values (3, 'cindy', 89); insert into student values (4, 'damn', 90); insert into student values (5, 'Ella ', 73); insert into student values (6, 'frado', 61 ); insert into student values (7, 'gill', 9
If we have a table student that contains the following fields and data:
Drop table student; Create Table student (ID int primary key, name nvarchar2 (50) not null, score number not null); insert into student values (1, 'Aaron ', 78); insert into student values (2, 'bill ', 76); insert into student values (3, 'cindy', 89); insert into student values (4, 'damn', 90); insert into student values (5, 'Ella ', 73); insert into student values (6, 'frado', 61 ); insert into student values (7, 'gill', 9
Tags: repeating collection pre order one directly does not contain deduplicationThe more union all is a direct connection, takes all values, records may have duplicate Union is a unique value, record is not duplicated 1. The syntax of UNION is as follows: [SQL Statement 1] UNION [SQL Statement 2]2. The
SQL Union and UNION ALL operatorsThe UNION operator is used to combine the result set of two or more SELECT statements.Note that the SELECT statement inside the UNION must have the same number of columns. The column must also have a similar data type. Also, the order of the columns in each SELECT statement must be the
The Union and JOIN statements in SQL are very similar, but the union has a constraint: two SQL statements produce a field that needs to be the same type of data, and the final result will see a different data value.
Format:
[SQL Statement 1]UNION[SQL Statement 2]
For example:
Table Store_info
and table Internet_sales
Use the
SQL union and SQL Union all usage
SQL Union operator
The Union operator is used to merge the result sets of two or more select statements.
Note that the SELECT statement inside the Union must haveSame quantity. Columns must also haveSimilar data types. In additionSequenceMus
A view is created based on three 10 million rows. Table links are implemented by Union. The following is an example of SQL:
Create view emaillogviewWith schemabindingAsSelect datatime, username, sourceip, destip, emailfrom, emailto, emailcc, emailbcc, emailsub, emaildate, orderid from DBO. emaillog
Union
Select datatime, username, sourceip,Destip, emailfrom, emailto, emailcc, emailbcc, emailsub, emaildate,
Union)Is a data type. It provides a way to share buckets between members of different types of data, and can realize automatic type conversion between members of different types of data. A consortium object can only store values of one member at a time.The size of the memory of the Union depends on the members with the largest number of bytes, rather than the sum. The U
One Limit of Union is that the columns generated by two SQL statements must be of the same data type. In addition, when we use the Union command, we only see different data values (similar to select distinct ). Union only Concatenates the two results and displays them together. It does not join two tables.
The syntax of union
One limitation of union is that two SQL statements produce a field that needs to be the same type of data. In addition, when we use the Union directive, we will only see different data values (similar to SELECT DISTINCT). The union simply joins the two results together to show that it is not linked to two tables.
The UNION
When we need to display the results of two SELECT statements as a whole, we need to use either the Union or the union ALL keyword. The Union works by combining multiple results together to display them. The difference between union and Uinon all is that the union will weigh
Document directory
Employees_china:
Employees_usa:
Instance
Result
Instance:
Result
Union
The Union command is used to select related information from two tables, similar to the join command. However, when the Union command is used, the Data Types of all selected columns should be the same.
NOTE: If Union is us
Several well-known result set operation commands have been tested in detail today, and some problems have been found.
Suppose we have a table student, which includes the following fields and data:
drop table student;create table student(id int primary key,name nvarchar2(50) not null,score number not null);insert into student values(1,'Aaron',78);insert into student values(2,'Bill',76);insert into student values(3,'Cindy',89);insert into student values(4,'Damon',90);insert into student values(5,'
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.