Home > database >  Simple Query - what's wrong with it?
Simple Query - what's wrong with it?

Time:07-30

SELECT * FROM buildings
where building_name not in
(select building from employees)

I'm trying to answer exercise 2 with the above (try it yourself here: https://sqlbolt.com/lesson/select_queries_with_nulls), but it's not returning anything. Is it a problem with the site or my query?

Thanks!

CodePudding user response:

There is a problem with null values. Thats why you have to ignore it in the subquery:

SELECT * FROM buildings 
where building_name  not in
(select building from employees where building is not null)

CodePudding user response:

I checked your query, according to the question that was on the site, you can easily extract the desired data using a sub-query.

in this query first of all we get list of building name that have employees after that get list of building not have any employees

select * from buildings where building_name not in (select building from employees where building not null group by building)

  •  Tags:  
  • sql
  • Related