开发者

MySQL query for multiple tables being secondary tables multiple items?

I have a query where I currently get information from 2 tables like this:

SELECT g.name 
FROM site_access b 
    JOIN groups g 
        ON b.group_id = g.id 
WHERE b.site_id = 1 
ORDER BY g.status ASC

Now I wanted to have another table with this query but this one table would return more then 1 row is that possible at all ?

All I could make was it pull 1 row from that table, the field I want is a string field and it is ok to join the result with a separator too as long as all the matchs can be pulled together in this query.

If you need more information about the tables or anything feel free to say I didnt think it would be needed as this is mostly an example of how to pull multiple rows from a join/select query.

UPDATE of what the above query would result:

Admin
Member
Banned

Now with my 3rd table each access have commands they are allowed to use so this 3rd table would list what commands each one has access to, example:

开发者_运维问答
Admin - add, del, announce
Member - find
Banned - none

UPDATE2:

  • site_access

    site_id
    group_id
    
  • groups

    id
    name
    status
    
  • groups_commands

    group_id
    command_id
    
  • commands

    id
    name
    


SELECT g.name, GROUP_CONCAT(c.command) AS commands
FROM site_access b 
    JOIN groups g 
        ON b.group_id = g.id 
    JOIN groups_commands gc
        ON g.id = gc.group_id
    JOIN commands c
        ON gc.command_id = c.id
WHERE b.site_id = 1 
GROUP BY g.name
ORDER BY g.status ASC
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜