- SQL - Discussion
- SQL - Useful Resources
- SQL - Useful Functions
- SQL - Quick Guide
- SQL - Questions and Answers
- SQL - Datatype Functions
- SQL - Conversion Functions
- SQL - JSON Functions
- SQL - Cursor Functions
- SQL - Logical Functions
- SQL - Statistical Functions
- SQL - Text & Image Functions
- SQL - Numeric Functions
- SQL - Aggregate Functions
- SQL - String Functions
- SQL - Date Functions
- SQL - Database Tuning
- SQL - IN vs EXISTS
- SQL - Group By vs Order By
- SQL - Common Table Expression
- SQL - Cursors
- SQL - Date & Time
- SQL - Auto Increment
- SQL - Using Sequences
- SQL - Handling Duplicates
- SQL - Sub Queries
- SQL - Transactions
- SQL - NULL Values
- SQL - Stored Procedures
- SQL - Default Constraint
- SQL - Check Constraint
- SQL - Null Functions
- SQL - Min & Max
- SQL - Hosting
- SQL - Injection
- SQL - Comments
- SQL - Wildcards
- SQL - Non-Clustered Index
- SQL - Clustered Index
- SQL - Unique Index
- SQL - Primary Key
- - 工会诉Join
- SQL - Inner Join
- SQL - Using Joins
- SQL - Aliases
- SQL - EXCEPT Operator
- SQL - INTERSECT Operator
- SQL - UNION vs UNION ALL
- SQL - UNION Operator
- SQL - BETWEEN Operator
- SQL - NOT NULL
- SQL - IS NOT NULL
- SQL - IS NULL
- SQL - NOT EQUAL
- SQL - NOT Operator
- SQL - CASE
- SQL - EXISTS Operator
- SQL - ANY, ALL Operators
- SQL - IN Operator
- SQL - LIKE Operator
- SQL - BOOLEAN (BIT) Operator
- SQL - AND & OR
- SQL - Having Clause
- SQL - Group By Clause
- SQL - Order By Clause
- SQL - Distinct Clause
- SQL - Top Clause
- SQL - Where Clause
- SQL - Rename Views
- SQL - Drop Views
- SQL - Update Views
- SQL - Create Views
- SQL - Sorting Results
- SQL - Delete Query
- SQL - Update Query
- SQL - Insert Into Select
- SQL - Select Into
- SQL - Select Query
- SQL - Insert Query
- SQL - Constraints
- SQL - Delete Table
- SQL - Drop Table
- SQL - Alter Tables
- SQL - Temporary Tables
- SQL - Clone Tables
- SQL - Truncate Table
- SQL - Rename Table
- SQL - Show Tables
- SQL - Create Table
- SQL - Backup Database
- SQL - Show Database
- SQL - Rename Database
- SQL - Select Database
- SQL - Drop Database
- SQL - Create Database
- SQL - Expressions
- SQL - Operators
- SQL - Data Types
- SQL - Syntax
- SQL - Databases
- SQL - RDBMS Concepts
- SQL - Overview
- SQL - Home
5. 图瓦卢
- 页: 1
- 页: 1
- 结构-创建指数
- 页: 1
- 页: 1
- 页: 1
- SQL - Foreign Key
- 文 件
- ∗ E/CN.6/2009/1。
- 页: 1
- 页: 1
- 文 件
- 页: 1
- 页: 1
- 文 件
- 页: 1
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
UNION vs JOIN
该中心提供各种关系操作者,处理多个表格在关系数据库中传播的数据。 其中,UNION和JOIN的查询基本上用于合并多个表格的数据。
Even though they are both used for the same purpose, i.e. to combine tables, there are many differences between the working of these operators. The major difference is that the UNION operator combines data from multiple similar tables irrespective of the data relativity, whereas, the JOIN operator is only used to combine relative data from multiple tables.
Working of UNION
UNION是KQ的一个经营/企业类型,与联盟运营商在关系方面的类似工作。 它只是将多个符合工会的表格的信息结合起来。
这些表格如果符合以下条件,即符合工会的要求:
The tables to be combined must have same number of columns with the same datatype.
The number of rows need not be same.
一旦达到这些标准,联合国构想的运营商将全部从多个表格中回收,然后将重复浏览作为结果表。
Following is the syntax of UNION operator in SQL − 让我们首先创建两个表格“CourSES_PICKED”和“EXTRA_COURSES_PICKED”,其数据类型相同。 创建表格 COURSES_PICKED, 采用以下程序: 在下文所述问询的帮助下,将数值列入消费物价指数表中: 创建表格 采用以下程序: 下面是将价值观列入贸易与投资司表格的问题。 现在,让我们努力利用“联合国意见”把这两个表格合并为“灯塔”; 执行联合国意见后获得的表格是: 若因业务将多个相关表格的信息根据其共同领域合并为一个表格。 In this operation, every row of the first table will be combined with every row of the second table. The resultant table obtained will contain the rows present in both tables. This operation can be used with various clauses pke ON, WHERE, ORDER BY, GROUP BY etc. 共有两种婚姻: Inner Join Outer Join 加入的基本类型是内部的Join,只收回共同栏的对应值。 这是一起违约。 其他加入“十字”组织、“自然儒昂”、“有条件的约恩”等都是内华人。 外包商在表上包括表上表上与表相匹配的和未配对的行。 它分为不同的子类,如Join、Join和Fud Join。 尽管合并运作可以合并多个表格,但合并两个表格的最简单方式是不使用《欧安办事处条款》以外的任何条款。 以下是Joinkou行动的基本辛迪加—— In the following example, we will try to join the same tables we created above, i.e., COURSES_PICKED and EXTRA_COURSES_PICKED, using the query below - 下表将列出: 正如我们在上文列举的例子中看到的那样,“联合国决策”经营者只是在符合工会的表格上受到迫害,而“国际自由行动网”经营者则加入两个不需要兼容但应该相关的表格。 让我们总结以下这些询问之间的所有区别:Syntax
SELECT * FROM table1
UNION
SELECT * FROM table2;
Example
CREATE TABLE COURSES_PICKED(
STUDENT_ID INT NOT NULL,
STUDENT_NAME VARCHAR(30) NOT NULL,
COURSE_NAME VARCHAR(30) NOT NULL
);
INSERT INTO COURSES_PICKED VALUES(1, JOHN , ENGLISH );
INSERT INTO COURSES_PICKED VALUES(2, ROBERT , COMPUTER SCIENCE );
INSERT INTO COURSES_PICKED VALUES(3, SASHA , COMMUNICATIONS );
INSERT INTO COURSES_PICKED VALUES(4, JULIAN , MATHEMATICS );
CREATE TABLE EXTRA_COURSES_PICKED(
STUDENT_ID INT NOT NULL,
STUDENT_NAME VARCHAR(30) NOT NULL,
EXTRA_COURSE_NAME VARCHAR(30) NOT NULL
);
INSERT INTO EXTRA_COURSES_PICKED VALUES(1, JOHN , PHYSICAL EDUCATION );
INSERT INTO EXTRA_COURSES_PICKED VALUES(2, ROBERT , GYM );
INSERT INTO EXTRA_COURSES_PICKED VALUES(3, SASHA , FILM );
INSERT INTO EXTRA_COURSES_PICKED VALUES(4, JULIAN , PHOTOGRAPHY );
SELECT * FROM COURSES_PICKED
UNION
SELECT * FROM EXTRA_COURSES_PICKED;
Output
+------------+--------------+--------------------+
| STUDENT_ID | STUDENT_NAME | COURSE_NAME |
+------------+--------------+--------------------+
| 1 | JOHN | ENGLISH |
| 1 | JOHN | PHYSICAL EDUCATION |
| 2 | ROBERT | COMPUTER SCIENCE |
| 2 | ROBERT | GYM |
| 3 | SASHA | COMMUNICATIONS |
| 3 | SASHA | FILM |
| 4 | JULIAN | MATHEMATICS |
| 4 | JULIAN | PHOTOGRAPHY |
+------------+--------------+--------------------+
Working of JOIN
Syntax
SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name = table2.column_name;
Example
SELECT c.STUDENT_ID, c.STUDENT_NAME, COURSE_NAME, COURSES_PICKED FROM COURSES_PICKED c
JOIN EXTRA_COURSES_PICKED e
ON c.STUDENT_ID = e.STUDENT_ID;
Output
+------------+--------------+------------------+--------------------+
| STUDENT_ID | STUDENT_NAME | COURSE_NAME | COURSES_PICKED |
+------------+--------------+------------------+--------------------+
| 1 | JOHN | ENGLISH | PHYSICAL EDUCATION |
| 2 | ROBERT | COMPUTER SCIENCE | GYM |
| 3 | SASHA | COMMUNICATIONS | FILM |
| 4 | JULIAN | MATHEMATICS | PHOTOGRAPHY |
+------------+--------------+------------------+--------------------+
UNION Vs JOIN
Advertisements
UNION
JOIN
UNION operation is only performed on tables that are union compatible, i.e., the tables must contain same number of columns with same data type.
JOIN operation can be performed on tables that has at least one common field between them. The tables need not be union compatible.
The data combined will be added as new rows of the resultant table.
The data combined will be adjoined into the resultant table as new columns.
This works as the conjunction operation.
This works as an intersection operation.
UNION removes all the duppcate values from the resultant tables.
JOIN retains all the values from both tables even if they’re redundant.
UNION does not need any additional clause to combine two tables.
JOIN needs an additional clause ON to combine two tables based on a common field.
It is mostly used in scenarios pke, merging the old employees pst in an organization with the new employees pst.
This is used in scenarios where merging related tables is necessary. For example, combining tables containing customers pst and the orders they made.