I have a database containing creatures from a game.
2 tables:
"creature_template" containing all the data relative to the creatures
"creature" containing the information about the location of the creatures in game.
Here is the code:
DELETE FROM
creature
WHERE
id not in
(SELECT DISTINCT
b.id
FROM
creature_template a inner join creature b on a.entry = b.id
WHERE
b.map != 571
AND a.`type` = 1
AND a.`type` = 10
);
The type is the type of the creature (1 = beast, 10 = not specified)
What I want to do is to delete all the creatures that are on the map #571 and that are not beasts (type=1) or not specified (type=10).
The "map" column is in the "creature" table while the "type" column is in the "creature_template" table.
Each creatures in the game is identified in the database by an ID. The "creature" table has a column called "id" which contains these IDs while the equivalent in the "creature_template" table is a column called "entry".
So what I must do is to select all the creatures that are on the map #571, then exclude all the type 1 and 10 and delete the rest.
Problem is that when I execute the code above, I get the error saying "You can't specify target table 'creature' for update in FROM clause"
I did a couple of research here on stackoverflow and tried a few solutions I found.
...I ended up deleting all the data from the "creature" table. Luckily I got the data back from a backup I did yesterday.
Any idea how to solve my problem?