A
A
Abc Edc2015-09-30 09:25:33
MySQL
Abc Edc, 2015-09-30 09:25:33

Is it even possible to make such a query in Mysql?

select all roles whose access is equal to the access of the selected role or (there are fewer accesses but they are equal, there are no others)

select * from roles 
left join roles_routes 
on roles.id = roles_routes.role_id 
where roles_routes.access  in (select access from roles_routes where role_id=1)

That is, now I get It is f6b4490f41c743fa816be336f0c1d657.png
necessary to receive only roles (I don’t know if it’s possible to immediately remove attached tabs with joins), but okay, this is not the first necessity, it’s okay.
Secondly, role_id =1 (here for example) is a moderator, and I'm trying to take by moderator only those roles whose access in the associated table is weaker than the moderator or equal to the moderator. That is, access's are either equal in number and they are equal in value with access's of the role by which I choose others, or their number is less, but their values ​​are equal to those access by the role of which I choose. That is, left access cannot be maybe.
that is, the Moderator role can contain NewsModerator , SomeModerator , but NewsModerator cannot take SomeModerator (that is, other than news) . For example, the role of SuperAdmin (because it has the same access as all access can select all other roles)
If the above is written very clumsily
Select all roles where access is equal to access's of this role in quantity and value, or the number of access for this role is greater than that of those that we are trying to select but the values ​​are the same

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gregory, 2015-09-30
@gleber1

... where roles_routes.access  in (select access from roles_routes where role_id=1)

Judging by this piece, a rake is obtained ... I usually first make a request to get access, and then, having an exact and clear value, I set a request for a list. That is something like this:
and than
but I do all this in PHP, so I can substitute the values ​​​​from the first request as you like ...

M
Max, 2015-09-30
@MaxDukov

understood nothing. what

you need to somehow add a condition only so that if access is left, then do not take role
?
even better, give the output of DESC roles_routes and DESC roles with an example of data, what your script outputs and what you want to get

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question