let's imagine that i have a simple table like this:
id - record id
char_id - character id
level_id - level id, that available for character
this is content example:
0 1 1
1 1 2
what's mean that character with id 1 has access to levels 1 and 2.
What keywords or constructions i need to use, if i want to get:
char_id of those characters, that has access to any two levels?
char_id of those, who has access to single level only and no more?
char_id of those, who has same levels available?
char_id of those, who has different levels available?
that blows my mind... could anyone recommend something?
For the first two options, use HAVING
:
-- To check for access to levels 1 and 2
SELECT char_id
FROM MyTable
WHERE level_id IN (1,2)
GROUP BY Char_Id
HAVING COUNT(*) = 2
-- to check for access to only one (unspecified) level
SELECT char_id
FROM MyTable
GROUP BY Char_ID
HAVING COUNT(*) = 1
The other two options you need to elaborate some more.
Do you only want exact matches between different char_ids? As in, these two characters both have access to the exact same list of levels?
The last option would just be the opposite of the above once you work out what exactly you want.