SQL Delete duplicate rows (all or distinct)

Source: Internet
Author: User

SQL Delete duplicate rows (all or distinct)
/*
Delete a duplicate row SELECT statement Use the all or distinct option to display all rows in the table that meet the criteria, or delete duplicate rows of data, default to all. When using the distinct option, only one row is reserved for all duplicate rows of data in the result set returned by select

We can also use it to get rid of duplicate data.

Combining two tables to remove duplicate data (mainly in table 2), we will get the following table:

A b

A 1

b 0

C 0

D 0

E 4

Select A,b from table 1 where a does (select a from table 2)

Union

Select A,b from Table 2

Distinct syntax

Select distinct "field name" from "Table name"

SQL UNION ALL syntax

Select COLUMN_NAME (s) from table_name1 UNION ALL SELECT COLUMN_NAME (s) from table_name2

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.