Home > Database > Mysql Tutorial > body text

sql UNION过滤重复记录语句并取得不重复的数据

WBOY
Release: 2016-06-07 17:47:08
Original
1643 people have browsed it

//我们一般是用union all 改成union看一下,联合查询显示不重复的记录哦。

sql UNION过滤重复记录语句并取得不重复的数据

$sql ="UNION ALL->UNION
--------------------
--以下句子如何取得不重复的数据?
SELECT DISTINCT TOP 100 PERCENT kirinLDS.dbo.tbl人员调整.部门名 AS 部门名
FROM kirinLDS.dbo.tbl人员 INNER JOIN
  kirinLDS.dbo.tbl定单 ON kirinLDS.dbo.tbl人员.工号 = kirinLDS.dbo.tbl定单.业务员 INNER JOIN
  kirinLDS.dbo.tbl人员调整 ON kirinLDS.dbo.tbl人员.姓名 = kirinLDS.dbo.tbl人员调整.人员
WHERE (LEFT(kirinLDS.dbo.tbl定单.会计月, 4) = '2009')

UNION

SELECT DISTINCT TOP 100 PERCENT kirinSZ.dbo.tbl人员调整.部门名 AS 部门名
FROM kirinSZ.dbo.tbl人员 INNER JOIN
  kirinSZ.dbo.tbl定单 ON kirinSZ.dbo.tbl人员.工号 = kirinSZ.dbo.tbl定单.业务员 INNER JOIN
  kirinSZ.dbo.tbl人员调整 ON kirinSZ.dbo.tbl人员.姓名 = kirinSZ.dbo.tbl人员调整.人员
WHERE (LEFT(kirinSZ.dbo.tbl定单.会计月, 4) = '2009')

UNION

SELECT DISTINCT TOP 100 PERCENT kirinLDSbj.dbo.tbl人员调整.部门名 AS 部门名
FROM kirinLDSbj.dbo.tbl人员 INNER JOIN
  kirinLDSbj.dbo.tbl定单 ON kirinLDSbj.dbo.tbl人员.工号 = kirinLDSbj.dbo.tbl定单.业务员 INNER JOIN
  kirinLDSbj.dbo.tbl人员调整 ON kirinLDSbj.dbo.tbl人员.姓名 = kirinLDSbj.dbo.tbl人员调整.人员
WHERE (LEFT(kirinLDSbj.dbo.tbl定单.会计月, 4) = '2009')
";
//我们一般是用union all 改成union看一下,联合查询显示不重复的记录哦。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template