A
A
Alexander Karadiaur2021-10-07 13:17:19
SQLite
Alexander Karadiaur, 2021-10-07 13:17:19

Deletes not 1 record, but all at once. How to fix?

Have a request

DELETE FROM `records` 
WHERE `user_id` in 
(SELECT `user_id` FROM `records` WHERE `user_id` = ? ORDER BY `date` DESC LIMIT 1)

It should delete the last entry, but deletes everything at once. How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-sem, 2021-10-07
@twiwter

It is necessary to delete not by the user_id condition, but return the id of a specific record and delete it
Something like

DELETE FROM `records` 
WHERE `id` in 
(SELECT `id` FROM `records` WHERE `user_id` = ? ORDER BY `date` DESC LIMIT 1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question