1
Assuming I have 3 tables: Company, Users and Users (which relates the other two tables)
Enterprise
+----+----------+--+
| ID | NOME | |
+----+----------+--+
| 1 | Empresa1 | |
| 2 | Empresa2 | |
| 3 | Empresa3 | |
| 4 | Empresa4 | |
+----+----------+--+
Users
+----+--------+--+
| ID | NOME | |
+----+--------+--+
| 1 | Joao | |
| 2 | Pedro | |
| 3 | Maria | |
| 4 | Fátima | |
+----+--------+--+
`
Usuariosempresa
+----+------------+------------+--+
| ID | usuario_id | empresa_id | |
+----+------------+------------+--+
| 1 | 1 | 1 | |
| 2 | 1 | 2 | |
| 3 | 2 | 1 | |
| 4 | 2 | 3 | |
| 5 | 3 | 1 | |
| 6 | 3 | 2 | |
| 7 | 3 | 3 | |
+----+------------+------------+--+
I would like to select all records from the Usuariosempresa table where there is no relationship between User and Company. In this example it would be something like this:
Upshot
+------+------------+------------+
| ID | usuario_id | empresa_id |
+------+------------+------------+
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| null | 1 | 3 |
| null | 1 | 4 |
| 3 | 2 | 1 |
| null | 2 | 2 |
| 4 | 2 | 3 |
| null | 2 | 4 |
| 5 | 3 | 1 |
| 6 | 3 | 2 |
| 7 | 3 | 3 |
| null | 3 | 4 |
| null | 4 | 1 |
| null | 4 | 2 |
| null | 4 | 3 |
| null | 4 | 4 |
+------+------------+------------+
I have put all records to illustrate, but I would like to select only those records that are NOT related ( from the example those that are null )