Join Table query, removing duplicate values, searching for redundant duplicate records in the table, and searching for rows with no duplicate records in the table

Source: Internet
Author: User

Select * from table1

Select * from table2

 

Select a. *, B. * from table1 a, table2 B where a. id = B. e

-- Query if column X of Table 1 has repeated values, take only one
Select min (id) as id, B, c from table1 group by B, c order by id asc

 

-- 1. Search for redundant duplicate records in the Table. duplicate records are determined based on a single field (peopleId ).
Select * from table1 where B in (select B from table1 group by B having count (B)> 1)

-- 1. Search for rows with no repeated records in the table
Select * from table1 where B in (select B from table1 group by B having count (B) = 1)

 

 

Select. *, B. id, B. e from table1 a inner join (select min (id) as id, e from table2 group by e) B on. id = B. e

 

-- Query records associated with two tables that are not repeated
Select aa. *, bb. f from (select. *, B. ids, B. e from table1 a inner join (select min (id) as ids, e from table2 group by e) B on. id = B. e) aa inner join table2 bb on aa. ids = bb. id

Name: GoldChao

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.