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

SQL query to check if a value isn't present

First of all, I really don’t know how to formulate my question.

I have different companies in a database.

I would like to know which companies doesn’t have an "analyst" profile.

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

Here is my query:

select
t.name as "name"
t.pre as "first name"
t.id as "# account"
t.profile as "Profile"
b.cod_miss as "Mission"
b.df_missn as "End date"


from sr.v t 
inner join od.e_lds on t.niu_ld = b.niu_ld
where b.cod_miss = 'APPROV'
and t.profile = 'Analyst'

This query gives me all the analyst for every companies in my database.
But I would like to have all the companies that does NOT have any analyst.
how do I do it? I tried using ‘and t.profile <> ‘analyst’ " but obviously this is not working well…

>Solution :

If I understood you correctly, that would be not exists. Something like this:

select *
from sr.v 
where not exists (select null 
                  from od.e_lds b
                  where b.niu_ld = t.niu_ld
                    and t.profile = 'Analyst'
                 );
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