Jows
Jows

Reputation: 897

Php MySQL - Delete all rows by limit

I want to delete all rows expect the 5 first rows.

/*example of the $count is equal to 5 */
$count=$xml->table->records->attributes();

This is my table:

xml_id  
   1
   2
   3
   4
   5
   6
   7
   8
   9
   10

The result would be like this

xml_id  
   1
   2
   3
   4
   5

The above 5 will be deleted.

Upvotes: 0

Views: 604

Answers (1)

Charaf JRA
Charaf JRA

Reputation: 8334

Try this query :

DELETE
FROM Table1
WHERE xml_id  NOT IN
    (SELECT xml_id  
     FROM Table1
     LIMIT 5)

Upvotes: 2

Related Questions