Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get table rows that are not in another table with a condition?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

+------------+----+
| 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
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading