Deleting all rows from database except first two rows in oracle

Mohsin Chaudhari

Hello I have a problem while deleting rows , I want to keep two rows in database and delete all other rows i found a query in this link for delete row but It is gives mysql Syntax limit function. but in oracle no limit variable available . how can i do the same?

DELETE FROM Table
  WHERE DateColumn NOT IN (SELECT DateColumn 
                             FROM Table 
                         GROUP BY date(DateColumn) 
                         ORDER BY DateColumn DESC
                            LIMIT 2);
San

This cab be achieved through this query

DELETE FROM TABLE 
 WHERE ROWID NOT IN
    (SELECT ROWIDS FROM (SELECT MIN(ROWID) ROWIDS 
                           FROM TABLE 
                          GROUP BY DATECOLUMN
                          ORDER BY DATECOLUMN DESC)
      WHERE ROWNUM <= 2);

The inner most query will return min of rowid's from table and then the immediate outer query will select only two rows to be avoided in the outermost delete.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

extract all rows from file_1 except those with first two columns matching the first two columns from file_2

From Dev

Deleting first two rows from a CSV using PIG or HIVE

From Dev

Deleting first two rows from a CSV using PIG or HIVE

From Dev

Oracle: Get All Rows Except One

From Dev

Deleting rows from two tables related by constraint

From Java

Deleting all rows from Cassandra cql table

From Dev

not getting all rows from the database

From Dev

not getting all rows from the database

From Dev

Retrieve all rows from table except few rows in laravel

From Dev

Error while deleting last two rows data with condition from database in Android it deletes only 1 row

From Dev

asp.net how to remove all the rows from a table except the first one

From Dev

Add List Validation to Column except the first two rows

From Dev

Conditionally deleting rows in MySQL Database

From Dev

Deleting rows when two blank rows are concurrent

From Dev

Query performance increase from deleting rows in SQL database?

From Dev

Select EntireColumn from ActiveCell, except first 3 rows

From Dev

Remove duplicate rows from table except for first timestamp of each day

From Dev

Delete all rows except rows with specified entries

From Dev

Delete all rows except rows with specified entries

From Dev

Get all rows apart from first and last

From Dev

Deleting all rows from table that share the same ID

From Dev

Deleting all rows from table, and resetting auto incrementation

From Dev

Get first two rows from first two groups

From Dev

How to delete all but first two rows in a table (headers is the first row)

From Dev

Codeigniter not returning all the rows from the database

From Dev

Display all rows of data from the database

From Dev

Is there a way to check for errors first from inserting in two related rows before saving in database

From Dev

Delete all rows from account, except most recent eleven

From Dev

SQL Select from all rows except this ID doesn't work

Related Related

  1. 1

    extract all rows from file_1 except those with first two columns matching the first two columns from file_2

  2. 2

    Deleting first two rows from a CSV using PIG or HIVE

  3. 3

    Deleting first two rows from a CSV using PIG or HIVE

  4. 4

    Oracle: Get All Rows Except One

  5. 5

    Deleting rows from two tables related by constraint

  6. 6

    Deleting all rows from Cassandra cql table

  7. 7

    not getting all rows from the database

  8. 8

    not getting all rows from the database

  9. 9

    Retrieve all rows from table except few rows in laravel

  10. 10

    Error while deleting last two rows data with condition from database in Android it deletes only 1 row

  11. 11

    asp.net how to remove all the rows from a table except the first one

  12. 12

    Add List Validation to Column except the first two rows

  13. 13

    Conditionally deleting rows in MySQL Database

  14. 14

    Deleting rows when two blank rows are concurrent

  15. 15

    Query performance increase from deleting rows in SQL database?

  16. 16

    Select EntireColumn from ActiveCell, except first 3 rows

  17. 17

    Remove duplicate rows from table except for first timestamp of each day

  18. 18

    Delete all rows except rows with specified entries

  19. 19

    Delete all rows except rows with specified entries

  20. 20

    Get all rows apart from first and last

  21. 21

    Deleting all rows from table that share the same ID

  22. 22

    Deleting all rows from table, and resetting auto incrementation

  23. 23

    Get first two rows from first two groups

  24. 24

    How to delete all but first two rows in a table (headers is the first row)

  25. 25

    Codeigniter not returning all the rows from the database

  26. 26

    Display all rows of data from the database

  27. 27

    Is there a way to check for errors first from inserting in two related rows before saving in database

  28. 28

    Delete all rows from account, except most recent eleven

  29. 29

    SQL Select from all rows except this ID doesn't work

HotTag

Archive