How to write a query in MYSQL?

There are 3 tables:
sm_admin ( id, identity , sid)
sm_groups (id, name)
sm_admins_groups(admin_id, group_id)
You must select one request all names of groups that belong to the admin with your chosen identity and sid
And the second query contains all the group names which do not belong to the admin with your chosen identity and sid.
Can't carry out the design with the JOIN 2 query, I was only able to 1:
SELECT d.id, d.name FROM sm_admins sm_admins_groups m JOIN r ON m.id=r.admin_id JOIN sm_groups d ON r.group_id=d.id WHERE m.identity = 'STEAM_0:1:427770368' AND m.sid='0'
March 19th 20 at 08:37
2 answers
March 19th 20 at 08:39
Solution
SELECT `name`
 FROM `sm_groups`
 WHERE `id` IN (
 SELECT `group_id`
 FROM `sm_admins_groups`
 WHERE `admin_id` IN (
 SELECT `id` 
 FROM `sm_admin`
 WHERE `identity` = :identity AND `sid` = :sid
)
 )

For the second request changing IN to NOT IN
March 19th 20 at 08:41
What's the problem to put the "unequally" in the query?
SELECT d.id, d.name 
FROM sm_admins m 
JOIN sm_admins_groups r ON m.id=r.admin_id 
JOIN sm_groups d ON r.group_id=d.id 
WHERE m.identity <> 'STEAM_0:1:427770368' AND m.sid <> '0'
If you put in the query unequally
sm_admins
id 2
identity STEAM_0:1:427770368
sid 0

sm_groups
id 1
OWNER name

id 2
name ADMIN

sm_admins_groups
admin_id 2
group_id 1

Issues:
1 OWNER
2 ADMIN - Trenton92 commented on March 19th 20 at 08:44

Find more questions by tags MySQL