Today, my boss told the below SQL query and went out without explaining it. Its working good.
But i want to know the way how it works.
SELECT NAME
FROM PERMISSIONTOKENS
WHERE ID IN (SELECT TOKENID
FROM ROLETOKENASSOCIATION
WHERE ROLEID = '1');
There are two queries here.
The inner query:
Will get all of the
TOKENIDs fromROLETOKENASSOCIATIONthat have aROLEIDof1.The outer query:
This will get all of the names from
PERMISSIONTOKENSthat have an ID that was in the result set of the inner query.You might be able to re-write this with joins instead of using
IN, if you don’t like the syntax ofIN.