SqlUNION filters duplicate record statements and obtains non-duplicated data

Source: Internet
Author: User
We usually use unionall to change to union. The union query shows records that are not repeated.

// We usually use union all to change to union. The union query shows records that are not repeated.

SQL UNION filters duplicate record statements and obtains non-duplicated data

$ SQL = "UNION ALL-> UNION
--------------------
-- How to obtain non-repeated data in the following sentence?
Select distinct top 100 PERCENT kirinLDS. dbo. tbl personnel adjustment. Department name AS department name
FROM kirinLDS. dbo. tbl personnel INNER JOIN
KirinLDS. dbo. tbl order ON kirinLDS. dbo. tbl personnel. employee ID = kirinLDS. dbo. tbl order. Clerk INNER JOIN
KirinLDS. dbo. tbl personnel adjustment ON kirinLDS. dbo. tbl personnel. Name = kirinLDS. dbo. tbl personnel adjustment. Personnel
WHERE (LEFT (kirinLDS. dbo. tbl order. monthly accounting, 4) = '123 ')

UNION

Select distinct top 100 PERCENT kirinSZ. dbo. tbl personnel adjustment. Department name AS department name
FROM kirinSZ. dbo. tbl personnel INNER JOIN
KirinSZ. dbo. tbl order ON kirinSZ. dbo. tbl personnel. employee ID = kirinSZ. dbo. tbl order. Salesman INNER JOIN
KirinSZ. dbo. tbl personnel adjustment ON kirinSZ. dbo. tbl personnel. Name = kirinSZ. dbo. tbl personnel adjustment. Personnel Adjustment
WHERE (LEFT (kirinSZ. dbo. tbl order. monthly accounting, 4) = '123 ')

UNION

Select distinct top 100 PERCENT kirinLDSbj. dbo. tbl personnel adjustment. Department name AS department name
FROM kirinLDSbj. dbo. tbl personnel INNER JOIN
KirinLDSbj. dbo. tbl order ON kirinLDSbj. dbo. tbl personnel. employee ID = kirinLDSbj. dbo. tbl order. Clerk INNER JOIN
KirinLDSbj. dbo. tbl personnel adjustment ON kirinLDSbj. dbo. tbl personnel. Name = kirinLDSbj. dbo. tbl personnel adjustment. Personnel Adjustment
WHERE (LEFT (kirinLDSbj. dbo. tbl order. monthly accounting, 4) = '123 ')
";
// We usually use union all to change to union. The union query shows records that are not repeated.

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.