SQL filters duplicate record statements and obtains data that is not duplicated

Source: Internet
Author: User
Keywords Network programming Database synthesis
Tags data get join name network network programming programming select

SQL Union filters duplicate record statements and obtains data that is not duplicated

$sql = "UNION all->union
--------------------
--How do I get data that is not duplicated in the following sentences?
SELECT DISTINCT top PERCENT KIRINLDS.DBO.TBL personnel adjustment. Department name as department name
From KIRINLDS.DBO.TBL personnel INNER JOIN
KIRINLDS.DBO.TBL orders on KIRINLDS.DBO.TBL personnel. Work Number = KirinLDS.dbo.tbl order. Salesman INNER JOIN
KIRINLDS.DBO.TBL personnel adjusted on KIRINLDS.DBO.TBL. Name = KIRINLDS.DBO.TBL personnel adjustment. Personnel
WHERE (Left (kirinLDS.dbo.tbl order. Fiscal month, 4) = ' 2009 ')

UNION

SELECT DISTINCT top PERCENT KIRINSZ.DBO.TBL personnel adjustment. Department name as department name
From KIRINSZ.DBO.TBL personnel INNER JOIN
KIRINSZ.DBO.TBL orders on KIRINSZ.DBO.TBL personnel. Work Number = KirinSZ.dbo.tbl order. Salesman INNER JOIN
KIRINSZ.DBO.TBL personnel adjusted on KIRINSZ.DBO.TBL. Name = KIRINSZ.DBO.TBL personnel adjustment. Personnel
WHERE (Left (kirinSZ.dbo.tbl order. Fiscal month, 4) = ' 2009 ')

UNION

SELECT DISTINCT Top PERCENT KIRINLDSBJ.DBO.TBL personnel adjustments. Department name as department name
from kirinLDSbj.dbo.tbl people INNER JOIN
  KIRINLDSBJ.DBO.TBL orders on KIRINLDSBJ.DBO.TBL personnel. Work Number = KirinLDSbj.dbo.tbl order. Clerk INNER JOIN
  KIRINLDSBJ.DBO.TBL personnel adjust on kirinLDSbj.dbo.tbl. Name = KIRINLDSBJ.DBO.TBL personnel adjustment. Person
WHERE (left) KIRINLDSBJ.DBO.TBL orders. Fiscal month, 4 = ' 2009 ')
;
We usually change Union all to Union. Look, the union query shows a record of not repeating oh.
 

Related Article

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.