博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL UNION
阅读量:7255 次
发布时间:2019-06-29

本文共 1088 字,大约阅读时间需要 3 分钟。

QL UNION is query that allows you to select related information from 2 tables, this is combine 2 SELECT statement into 1 and display it out.

UNION will only return DISTINCT value only. Which means will eliminate duplicate records that returned.

There are some condition that need to meet when using the UNION statement.

First SELECT statement must have the same column number if compare with 2nd SELECTStatement.
Data type also has to be same for both columns to combine.

The syntax is as follows:

SELECT [COLUMN NAME 1], [COLUMN NAME 2],… FROM [TABLE NAME 1]

UNION
SELECT [COLUMN NAME 1], [COLUMN NAME 2],… FROM [TABLE NAME 2]

EXAMPLE :

We have 2 table name GamesScores, GameScores_new.

Table GameScores

PlayerName Department Scores
Jason IT 3000
Irene IT 1500
Jane Marketing 1000
David Marketing 2500
Paul HR 2000
James HR 2000

Table GameScores_new

PlayerName Department Scores
Jason IT 3000
David Marketing 2500
Paul HR 2000
James HR 2000

SQL statement :

SELECT PlayerName FROM GameScores

UNION
SELECT PlayerName FROM GameScores_new

Result:

PlayerName
David
Irene
James
Jane
Jason
Paul

转载地址:http://bdkdm.baihongyu.com/

你可能感兴趣的文章
Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0
查看>>
mysql操作命令梳理(3)-pager
查看>>
opencv3——ANN算法的使用
查看>>
[OSG]OSG的相关扩展
查看>>
MVC ---- EF高级增删改
查看>>
使用wireshark分析tcp/ip报文之报文头
查看>>
magent实现memcached集群的一个问题
查看>>
php 下 html5 XHR2 + FormData + File API 上传文件
查看>>
利用函数来得到所有子节点号& 利用函数来取得最高级的节点号
查看>>
Linux驱动技术(三) _DMA编程
查看>>
各技术镜像整理
查看>>
[01分数规划]【学习笔记】
查看>>
【Go命令教程】12. go tool pprof
查看>>
Selenium2+Python自动化-处理浏览器弹窗(转载)
查看>>
Python基础(list和tuple)可变集合和‘不可变’集合
查看>>
BZOJ 1226: [SDOI2009]学校食堂Dining [DP 状压]
查看>>
nginx源码安装教程(CentOS)
查看>>
CSS margin详解
查看>>
greenplum 安装笔记
查看>>
URI是什么意思?URI和URL有什么区别?
查看>>