i want take typens from table 2 which are not in the first table and fulfill the conditions
i have table 1
+----+---------------+-------+
| ID | vacancyTypeID | orgId |
+----+---------------+-------+
| 1 | 4 | 25 |
| 2 | 2 | 25 |
| 3 | 3 | 25 |
| 4 | 4 | 24 |
| 5 | 1 | 22 |
+----+---------------+-------+
and table 2
+------------+----+
| typen | id |
+------------+----+
| teacher | 1 |
| teacher 2 | 2 |
| teacher 3 | 3 |
| teacher 4 | 4 |
| teacher 5 | 5 |
+------------+----+
i want get
all typen from table2 which are not in table 2 for with orgid = 25
i get nothing when try this
SELECT table2.*
FROM table2
LEFT JOIN table1 ON (table1.vacancyTypeID=table2.id)
where table1.vacancyTypeID is null table1.orgId = 25;
but i need
+------------+----+
| typen | id |
+------------+----+
| teacher | 1 |
| teacher 5 | 5 |
+------------+----+
>Solution :
I think this does what you want. Pick all the orgs where the id is not in the other list:
SELECT * FROM OrganizationTypes
WHERE id NOT IN (
SELECT vacancyTypeID FROM Vacancys WHERE orgId=25
);