On the MMORPG server I am refactoring, I have two tables. One for items and one for spells. Each item has up to 5 spells, so I went with a sparse matrix format, having 5 columns for spell identifiers.
The original developers of this structure preferred to use MyISAM, which does not support links, as a result of which the table of elements contains elements with non-existent spell identifiers. I want to find out which elements have the wrong spell identifiers in order to fix them and possibly eventually convert to InnoDB.
So far, I could only come up with the following:
SELECT COUNT(*)
FROM items
WHERE spellid_1 NOT IN (SELECT entry FROM research.spell)
OR spellid_2 NOT IN (SELECT entry FROM research.spell)
OR spellid_3 NOT IN (SELECT entry FROM research.spell)
OR spellid_4 NOT IN (SELECT entry FROM research.spell)
OR spellid_5 NOT IN (SELECT entry FROM research.spell);
Is there a more elegant way to do this?
EDIT: NULL spellid_n is considered valid, as it simply means that the item does not have a spell in this slot.
source
share