There are several problems with your example.
First, the DELETE query as is ends with a syntax error:
MariaDB [test]> delete from `employee` E where not exists(select 1 from `entreprise` a join `rooms` r on r.`ent_id` = a.`ent_id` and r.`room_id` = e.`room_id`);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'E where not exists(select 1 from `entreprise` a join `rooms` r on r.`ent_id` = a' at line 1
This is because you use multi-table syntax, but only partially. Apparently, you meant something like:
delete E from `employee` E where not exists(select 1 from `entreprise` a join `rooms` r on r.`ent_id` = a.`ent_id` and r.`room_id` = e.`room_id`);
It also fails, on the obvious reason:
ERROR 1146 (42S02): Table 'test.rooms' doesn't exist
So, in fact it should be this:
delete E from `employee` E where not exists(select 1 from `entreprise` a join `room` r on r.`ent_id` = a.`ent_id` and r.`room_id` = e.`room_id`);
Now, it indeed fails with
ERROR 1054 (42S22): Unknown column 'e.room_id' in 'on clause'
There are two reasons for that. First, you are mixing up lowercase and uppercase alias names. Since you are on Wheezy, I assume you are running with case-sensitive table names, so you shouldn't do mix them. Instead, it should be like this:
delete E from `employee` E where not exists(select 1 from `entreprise` a join `room` r on r.`ent_id` = a.`ent_id` and r.`room_id` = E.`room_id`);
But it still fails with the same error. Now we probably got to the problem which your report is actually about. ON clause can only refer to the operands in the JOIN, which `employee` is not. See http://dev.mysql.com/doc/refman/5.6/en/join.html – it's a long article, but it does actually say so, search for "can refer only".
Instead, this should work, and it does:
delete E from `employee` E where not exists(select 1 from `entreprise` a join `room` r on r.`ent_id` = a.`ent_id` where r.`room_id` = E.`room_id`);
There are several problems with your example.
First, the DELETE query as is ends with a syntax error:
This is because you use multi-table syntax, but only partially. Apparently, you meant something like:
It also fails, on the obvious reason:
So, in fact it should be this:
Now, it indeed fails with
There are two reasons for that. First, you are mixing up lowercase and uppercase alias names. Since you are on Wheezy, I assume you are running with case-sensitive table names, so you shouldn't do mix them. Instead, it should be like this:
But it still fails with the same error. Now we probably got to the problem which your report is actually about. ON clause can only refer to the operands in the JOIN, which `employee` is not. See http://dev.mysql.com/doc/refman/5.6/en/join.html – it's a long article, but it does actually say so, search for "can refer only".
Instead, this should work, and it does: