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

Is there any way to filter based on two tables

I have a query that gets data based on multiple tables

A(id) scientist with access
B(id, type) has employee and groups. Each with type.

X(id, state) has all employees
Y(id, state) has all groups
A.a will be either in X or in Y

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

select A.id, B.type 
from A
inner join B on A.id = B.id

I have two more tables

X (id, state) and Y (id, state)

And A.a could be either in X or in Y.

I don’t need any columns from X or Y. I need to remove from select those which have X.state="disabled"

>Solution :

Looks like you just need two NOT EXISTS.

select
  a.id,
  b.type 
from A a
inner join B b on a.id = b.id
  and not exists (select 1
    from x
    where x.id = a.id
      and x.state = 'disabled'
) and not exists (select 1
    from y
    where y.id = a.id
      and y.state = 'disabled'
);
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