A
A
Alex Ivanov2016-06-10 18:24:11
SQL
Alex Ivanov, 2016-06-10 18:24:11

How to delete the last user entry?

The task - to delete the last record of the user from the table.
I try like this

DELETE FROM `all` WHERE id = (SELECT id FROM `all` where userid='5' ORDER BY id DESC LIMIT 1)

But I get error
#1093 - You can't specify target table 'all' for update in FROM clause
subquery
SELECT id FROM `all` where userid='5' ORDER BY id DESC LIMIT 1

gives the correct id. Where did I go wrong with my design?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DuD, 2016-06-10
@Protossan

DELETE FROM all WHERE user_id=5 ORDER BY id DESC LIMIT 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question