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

Get opposite result of INNER JOIN

There is Table A and B

item_serial_no (Table A)  | forbidden_item_serial_no (Table B)
--------------            | --------------
1                         | 1
2                         | 3
3                         | 5
4                         | 7
5
6
7

When I use SQL:

SELECT
A.item_serial_no
FROM
A
INNER JOIN B ON A.item_serial_no = B.forbidden_item_serial_no

I will get 1,3,5,7.

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

But I would like to get negation of it, so the result would be like:

result query
------------
2
4
6

I am not SQL ninja and I have spent prety much time to solve this, but no success.
Thanx for help

>Solution :

One way of doing this is to use a LEFT JOIN:

SELECT
A.item_serial_no
FROM
A
LEFT JOIN B ON A.item_serial_no = B.forbidden_item_serial_no
WHERE B.forbidden_item_serial_no IS NULL
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