CREATE
VIEW `usergroupagina` AS
    SELECT
        `t`.`user_id` AS `user_id`,
        `t`.`group_id` AS `resource_id`
    FROM
        (SELECT
            `a`.`id` AS `user_id`, `b`.`id` AS `group_id`
        FROM
            (`users` `a`
        JOIN `resource` `b`)
        WHERE
            ((`a`.`id` = `b`.`responsible`)
                AND (`b`.`status` NOT IN (1 , 6))) UNION SELECT
            `a`.`id` AS `user_id`, `b`.`id` AS `group_id`
        FROM
            (`users` `a`
        JOIN `resource` `b`
        JOIN `resource_permission` `c`)
        WHERE
            ((`a`.`id` = `c`.`user`)
                AND (`b`.`id` = `c`.`resource`)
                AND (`c`.`permission` > 1)
                AND (`b`.`status` NOT IN (1 , 6)))) as t;

CREATE
VIEW `groupagina` AS
    SELECT
        `resource`.`id` AS `group_id`,
        `resource`.`name` AS `group_resource`,
        `resource`.`machine` AS `group_name`
    FROM
        `resource`
    WHERE
        `resource`.`status` NOT IN (1 , 6);