Skip to main content
deleted 232 characters in body
Source Link
Buster3650
  • 478
  • 2
  • 9
  • 23

For us it's important that only the EXACT same rows must be deleted, and only the last row must be saved. Our table looks like this (keep in mind that it looks like this before and after running query):

mysql> select * from Raw_Validated_backup;

+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
| id     | time_start          | time_end            | first_temp_lpn | first_WL | first_temp_lpn_validated | second_temp_lpn | second_WL | second_temp_lpn_validated | third_temp_lpn | third_WL | third_temp_lpn_validated | first_temp_rising | first_WR | first_temp_rising_validated | second_temp_rising | second_WR | second_temp_rising_validated | third_temp_rising | third_WR | third_temp_rising_validated |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
|   8355 | 2020-01-02 14:20:00 | 2020-01-02 15:20:00 |           2.48 |    -0.38 |                        1 |            2.46 |     -0.46 |                         1 |           2.43 |    -0.43 |                        1 |              2.43 |    -0.33 |                           1 |               2.27 |     -0.27 |                            1 |              2.26 |    -0.26 |                           1 |
|   8356 | 2020-01-02 14:40:00 | 2020-01-02 15:40:00 |           2.46 |    -0.46 |                        1 |            2.43 |     -0.43 |                         1 |           2.42 |    -0.32 |                        1 |              2.27 |    -0.27 |                           1 |               2.26 |     -0.26 |                            1 |              2.37 |    -0.27 |                           1 |
|   8357 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
| 830000 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+

Above should be corrected to this, after running a successful query:

mysql> select * from Raw_Validated_backup;

+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
| id     | time_start          | time_end            | first_temp_lpn | first_WL | first_temp_lpn_validated | second_temp_lpn | second_WL | second_temp_lpn_validated | third_temp_lpn | third_WL | third_temp_lpn_validated | first_temp_rising | first_WR | first_temp_rising_validated | second_temp_rising | second_WR | second_temp_rising_validated | third_temp_rising | third_WR | third_temp_rising_validated |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
|   8355 | 2020-01-02 14:20:00 | 2020-01-02 15:20:00 |           2.48 |    -0.38 |                        1 |            2.46 |     -0.46 |                         1 |           2.43 |    -0.43 |                        1 |              2.43 |    -0.33 |                           1 |               2.27 |     -0.27 |                            1 |              2.26 |    -0.26 |                           1 |
|   8356 | 2020-01-02 14:40:00 | 2020-01-02 15:40:00 |           2.46 |    -0.46 |                        1 |            2.43 |     -0.43 |                         1 |           2.42 |    -0.32 |                        1 |              2.27 |    -0.27 |                           1 |               2.26 |     -0.26 |                            1 |              2.37 |    -0.27 |                           1 |
| 830000 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+

For us it's important that only the EXACT same rows must be deleted, and only the last row must be saved. Our table looks like this (keep in mind that it looks like this before and after running query):

mysql> select * from Raw_Validated_backup;

+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
| id     | time_start          | time_end            | first_temp_lpn | first_WL | first_temp_lpn_validated | second_temp_lpn | second_WL | second_temp_lpn_validated | third_temp_lpn | third_WL | third_temp_lpn_validated | first_temp_rising | first_WR | first_temp_rising_validated | second_temp_rising | second_WR | second_temp_rising_validated | third_temp_rising | third_WR | third_temp_rising_validated |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
|   8355 | 2020-01-02 14:20:00 | 2020-01-02 15:20:00 |           2.48 |    -0.38 |                        1 |            2.46 |     -0.46 |                         1 |           2.43 |    -0.43 |                        1 |              2.43 |    -0.33 |                           1 |               2.27 |     -0.27 |                            1 |              2.26 |    -0.26 |                           1 |
|   8356 | 2020-01-02 14:40:00 | 2020-01-02 15:40:00 |           2.46 |    -0.46 |                        1 |            2.43 |     -0.43 |                         1 |           2.42 |    -0.32 |                        1 |              2.27 |    -0.27 |                           1 |               2.26 |     -0.26 |                            1 |              2.37 |    -0.27 |                           1 |
|   8357 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
| 830000 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+

Above should be corrected to this, after running a successful query:

mysql> select * from Raw_Validated_backup;

+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
| id     | time_start          | time_end            | first_temp_lpn | first_WL | first_temp_lpn_validated | second_temp_lpn | second_WL | second_temp_lpn_validated | third_temp_lpn | third_WL | third_temp_lpn_validated | first_temp_rising | first_WR | first_temp_rising_validated | second_temp_rising | second_WR | second_temp_rising_validated | third_temp_rising | third_WR | third_temp_rising_validated |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
|   8355 | 2020-01-02 14:20:00 | 2020-01-02 15:20:00 |           2.48 |    -0.38 |                        1 |            2.46 |     -0.46 |                         1 |           2.43 |    -0.43 |                        1 |              2.43 |    -0.33 |                           1 |               2.27 |     -0.27 |                            1 |              2.26 |    -0.26 |                           1 |
|   8356 | 2020-01-02 14:40:00 | 2020-01-02 15:40:00 |           2.46 |    -0.46 |                        1 |            2.43 |     -0.43 |                         1 |           2.42 |    -0.32 |                        1 |              2.27 |    -0.27 |                           1 |               2.26 |     -0.26 |                            1 |              2.37 |    -0.27 |                           1 |
| 830000 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
added 91 characters in body
Source Link
Buster3650
  • 478
  • 2
  • 9
  • 23

Message we receive after running query: No errors, 0 rows affected, taking 40,4 s

Message we receive after running query: No errors, 0 rows affected, taking 40,4 s

Source Link
Buster3650
  • 478
  • 2
  • 9
  • 23

Delete duplicated rows MySQL

We want to delete duplicated rows on our MySQL database, and we have tried a lot of queries, but for unfortunately we haven't succeeded yet. We found this query on several posts, but didn't work either:

DELETE t1 FROM Raw_Validated_backup AS t1 INNER JOIN Raw_Validated_backup AS t2 
    ON t1.time_start=t2.time_start 
    AND t1.time_end=t2.time_end 
    AND t1.first_temp_lpn=t2.first_temp_lpn 
    AND t1.first_WL=t2.first_WL 
    AND t1.first_temp_lpn_validated=t2.first_temp_lpn_validated 
    AND t1.second_temp_lpn=t2.second_temp_lpn 
    AND t1.second_WL=t2.second_WL 
    AND t1.second_temp_lpn_validated=t2.second_temp_lpn_validated 
    AND t1.third_temp_lpn=t2.third_temp_lpn 
    AND t1.third_WL=t2.third_WL 
    AND t1.third_temp_lpn_validated=t2.third_temp_lpn_validated 
    AND t1.first_temp_rising=t2.first_temp_rising 
    AND t1.first_WR=t2.first_WR 
    AND t1.first_temp_rising_validated=t2.first_temp_rising_validated 
    AND t1.second_temp_rising=t2.second_temp_rising 
    AND t1.second_WR=t2.second_WR 
    AND t1.second_temp_rising_validated=t2.second_temp_rising_validated 
    AND t1.third_temp_rising=t2.third_temp_rising 
    AND t1.third_WR=t2.third_WR 
    AND t1.third_temp_rising_validated=t2.third_temp_rising_validated 
    AND t1.id<t2.id;

For us it's important that only the EXACT same rows must be deleted, and only the last row must be saved. Our table looks like this (keep in mind that it looks like this before and after running query):

mysql> select * from Raw_Validated_backup;

+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
| id     | time_start          | time_end            | first_temp_lpn | first_WL | first_temp_lpn_validated | second_temp_lpn | second_WL | second_temp_lpn_validated | third_temp_lpn | third_WL | third_temp_lpn_validated | first_temp_rising | first_WR | first_temp_rising_validated | second_temp_rising | second_WR | second_temp_rising_validated | third_temp_rising | third_WR | third_temp_rising_validated |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
|   8355 | 2020-01-02 14:20:00 | 2020-01-02 15:20:00 |           2.48 |    -0.38 |                        1 |            2.46 |     -0.46 |                         1 |           2.43 |    -0.43 |                        1 |              2.43 |    -0.33 |                           1 |               2.27 |     -0.27 |                            1 |              2.26 |    -0.26 |                           1 |
|   8356 | 2020-01-02 14:40:00 | 2020-01-02 15:40:00 |           2.46 |    -0.46 |                        1 |            2.43 |     -0.43 |                         1 |           2.42 |    -0.32 |                        1 |              2.27 |    -0.27 |                           1 |               2.26 |     -0.26 |                            1 |              2.37 |    -0.27 |                           1 |
|   8357 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
| 830000 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+

Above should be corrected to this, after running a successful query:

mysql> select * from Raw_Validated_backup;

+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
| id     | time_start          | time_end            | first_temp_lpn | first_WL | first_temp_lpn_validated | second_temp_lpn | second_WL | second_temp_lpn_validated | third_temp_lpn | third_WL | third_temp_lpn_validated | first_temp_rising | first_WR | first_temp_rising_validated | second_temp_rising | second_WR | second_temp_rising_validated | third_temp_rising | third_WR | third_temp_rising_validated |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+
|   8355 | 2020-01-02 14:20:00 | 2020-01-02 15:20:00 |           2.48 |    -0.38 |                        1 |            2.46 |     -0.46 |                         1 |           2.43 |    -0.43 |                        1 |              2.43 |    -0.33 |                           1 |               2.27 |     -0.27 |                            1 |              2.26 |    -0.26 |                           1 |
|   8356 | 2020-01-02 14:40:00 | 2020-01-02 15:40:00 |           2.46 |    -0.46 |                        1 |            2.43 |     -0.43 |                         1 |           2.42 |    -0.32 |                        1 |              2.27 |    -0.27 |                           1 |               2.26 |     -0.26 |                            1 |              2.37 |    -0.27 |                           1 |
| 830000 | 2020-01-02 15:00:00 | 2020-01-02 16:00:00 |           2.43 |    -0.43 |                        1 |            2.42 |     -0.32 |                         1 |           NULL |     NULL |                        0 |              2.26 |    -0.26 |                           1 |               2.37 |     -0.27 |                            1 |               2.2 |     -0.3 |                           1 |
+--------+---------------------+---------------------+----------------+----------+--------------------------+-----------------+-----------+---------------------------+----------------+----------+--------------------------+-------------------+----------+-----------------------------+--------------------+-----------+------------------------------+-------------------+----------+-----------------------------+