CONSULTA PROPOSTA
SELECT A.*
FROM acl_permissions A LEFT JOIN
(SELECT * FROM acl_group_permissions WHERE group_id=1) B
ON A.id = B.permissions_id WHERE B.id IS NULL;
SEUS DADOS DE AMOSTRA
DROP DATABASE IF EXISTS matt;
CREATE DATABASE matt;
USE matt
CREATE TABLE acl_permissions
(
id int not null auto_increment,
name varchar(32),
permission varchar(32),
primary key (id)
);
CREATE TABLE acl_group_permissions
(
id int not null auto_increment,
group_id int not null,
permissions_id int not null,
primary key (id)
);
INSERT INTO acl_permissions
(name,permission) VALUES
('Add User' ,'addUser'),
('Edit User' ,'editUser'),
('Delete User','deleteUser'),
('View User' ,'viewUser'),
('Test Name' ,'testPermission');
INSERT INTO acl_group_permissions
(group_id,permissions_id) VALUES
(1,1),(1,2),(1,3),(1,4),(2,4),(2,5);
SELECT * FROM acl_permissions;
SELECT * FROM acl_group_permissions;
SEUS DADOS DE AMOSTRAGEM CARREGADOS
mysql> DROP DATABASE IF EXISTS matt;
Query OK, 2 rows affected (0.39 sec)
mysql> CREATE DATABASE matt;
Query OK, 1 row affected (0.00 sec)
mysql> USE matt
Database changed
mysql> CREATE TABLE acl_permissions
-> (
-> id int not null auto_increment,
-> name varchar(32),
-> permission varchar(32),
-> primary key (id)
-> );
Query OK, 0 rows affected (0.29 sec)
mysql> CREATE TABLE acl_group_permissions
-> (
-> id int not null auto_increment,
-> group_id int not null,
-> permissions_id int not null,
-> primary key (id)
-> );
Query OK, 0 rows affected (0.30 sec)
mysql> INSERT INTO acl_permissions
-> (name,permission) VALUES
-> ('Add User' ,'addUser'),
-> ('Edit User' ,'editUser'),
-> ('Delete User','deleteUser'),
-> ('View User' ,'viewUser'),
-> ('Test Name' ,'testPermission');
Query OK, 5 rows affected (0.03 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> INSERT INTO acl_group_permissions
-> (group_id,permissions_id) VALUES
-> (1,1),(1,2),(1,3),(1,4),(2,4),(2,5);
Query OK, 6 rows affected (0.08 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM acl_permissions;
+----+-------------+----------------+
| id | name | permission |
+----+-------------+----------------+
| 1 | Add User | addUser |
| 2 | Edit User | editUser |
| 3 | Delete User | deleteUser |
| 4 | View User | viewUser |
| 5 | Test Name | testPermission |
+----+-------------+----------------+
5 rows in set (0.00 sec)
mysql> SELECT * FROM acl_group_permissions;
+----+----------+----------------+
| id | group_id | permissions_id |
+----+----------+----------------+
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 1 | 3 |
| 4 | 1 | 4 |
| 5 | 2 | 4 |
| 6 | 2 | 5 |
+----+----------+----------------+
6 rows in set (0.00 sec)
mysql>
CONSULTA PROPOSTA EXECUTADA
mysql> SELECT A.*
-> FROM acl_permissions A LEFT JOIN
-> (SELECT * FROM acl_group_permissions WHERE group_id=1) B
-> ON A.id = B.permissions_id WHERE B.id IS NULL;
+----+-----------+----------------+
| id | name | permission |
+----+-----------+----------------+
| 5 | Test Name | testPermission |
+----+-----------+----------------+
1 row in set (0.00 sec)
mysql>
DÊ UMA EXPERIÊNCIA !!!