Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return deleted rows in sqlite

Tags:

sql

sqlite

It's not efficient to do two queries like SELECT * FROM TABLE WHERE clause and then DELETE * FROM TABLE WHERE clause.

So I want to make DELETE query and return deleted rows (one query).

I tried to do:

DELETE OUTPUT DELETED.*
FROM table
WHERE clause

But I have an error:

SQLite exception: near "OUTPUT": syntax error

How to make it correctly or maybe there is another alternative way to return deleted rows?

like image 207
Kenenbek Arzymatov Avatar asked Apr 04 '17 13:04

Kenenbek Arzymatov


Video Answer


1 Answers

The DELETE statement has no OUTPUT clause.

After doing the SELECT, all the important data is in the cache, so the DELETE will run quickly.

And because SELECT plus DELETE is the only way, it is the most efficient way.

like image 199
CL. Avatar answered Sep 28 '22 06:09

CL.