I want to delete rows from a table "Book", where two colums have appeared before.
I successfully selected the ids of the rows wich should be deleted like so:
SELECT all_dupes.book_id
FROM (SELECT *
FROM Book as BBook NATURAL JOIN Book as BBBook
WHERE book_id NOT IN (SELECT book_id
FROM Book as BBook NATURAL JOIN Book as BBBook
GROUP BY buying_price,
selling_price
HAVING Count(*) = 1
ORDER BY book_id)
ORDER BY book_id) AS all_dupes
WHERE book_id NOT IN (SELECT book_id
FROM Book as BBook NATURAL JOIN Book as BBBook
GROUP BY buying_price,
selling_price
HAVING Count(*) >= 2
ORDER BY book_id);
…but when I try to delete the rows with
DELETE FROM Book
WHERE book_id IN (
<expression as above without tailing ;>
) ;
I get an error ERROR 1093 (HY000): Table 'Book' is specified twice, both as a target for 'DELETE' and as a separate source for data
I already tried to alias the table and to natural join the table to itself, like suggested in other questions regarding this issue.
Also I read quite some ammount of questions here, but they mostly are very specific and I don't get how to change my delete-query by the answers provided there.
What do I have to change in order to get this done? Splitting the expression is not an option (meaning there mustn't be two ;
, but just one expression).
Database used: MariaDB