ChrisCross
ChrisCross

Reputation: 101

Deleting the second last row from Mysql(Mariadb) database

So I can get the second last row from my database using

select* from hot_coffee_order order by OID desc limit 1,1

However when I try to delete this row using:

delete from hot_coffee_order order by OID desc limit 1,1

I encounter an error for some reason. Is there a way to delete the second last row from my database?

Upvotes: 0

Views: 95

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270583

It would be more complicated, but assuming that OID is unique, you can use a join:

delete hco
    from hot_coffee_order hco join
         (select hco2.*
          from hot_coffee_order hco2
          order by oid desc
          limit 1, 1
         ) hco2
         using (oid);

Upvotes: 1

Related Questions