In SQL, the statement that only one piece is left for deduplicating records is preferably explained

Updated on technology 2024-04-04
5 answers
  1. Anonymous users2024-02-07

    1 --Oracle deduplicates records, which can be operated using Oracle's unique rowid such as:

    delete from test1 where rowid not in (select max(rowid) from test1);

    Explanation: rowid is a virtual column, not a real column in the table, using the unique feature of rowid, you can remove duplicates.

    Recorded. 2 --mysql deduplicates the records.

    Idea: Use the distinct keyword to obtain unique records, and then create a new table to copy the records.

    1、create table test2 as select distinct * from test1;

    2、drop table test1;

    3、alter table test2 rename to test1;

    Explanation: Create a new table to copy the unique records, delete the original table, and rename the new table to the original table name. Finish.

  2. Anonymous users2024-02-06

    This can't be done in one step.

    You can find out the unique information and put it in the temporary table first.

    select distinct *

    into #a

    from table1

    Delete the original table.

    delete from table1

    Insert the information back into the original table.

    insert into table1

    select * from #a

  3. Anonymous users2024-02-05

    Use the distinct keyword to return a uniquely different record.

    Syntax: select distinct column name from table name.

  4. Anonymous users2024-02-04

    1. You can use the following statements to deal with it, and you can do it according to the annotations:

    Deduplicate the data and stage it in temporary table A.

    select distinct * into a from table1 where condition.

    delete table1 where --Note: Insert into table1 select * from a -- Insert into table1 select * from a -- Insert the staged data back into the database.

    drop table a -- Delete the temporary table.

    2. In addition, in the current database, it is recommended that each table should have a flag field to ensure that the records are not completely duplicated, otherwise it is very easy to have problems in practice.

  5. Anonymous users2024-02-03

    Add an auto-incrementing column to the table, then get the larger column through the statement and delete it.

Related questions
11 answers2024-04-04

In the deleted table of the trigger, the deleted row is saved. Just take it out and insert another table. >>>More

4 answers2024-04-04

First, create a temporary table, and then remove the data from the author table and put it into the temporary table. >>>More

10 answers2024-04-04

Step 3: Wait for the scan to complete and select the files in the same file that need to be deleted, and click Delete in the lower right corner to delete the duplicate files in batches, as shown in the figure below

21 answers2024-04-04

It is recommended that you write a stored procedure, and I will write one for your reference! cardno is a custom data type! It's easy to make mistakes with triggers. >>>More

5 answers2024-04-04

Since you don't know the primary key in your t hy cus install table, it's safer to use exists. >>>More