0

I know there are similar questions, but I can't find solution to what I need to do.

First of all I have 2 tables :

  • SD.Airlines (16k+ rows)
  • SD.AirlineRatings (405 rows)

I need to find which records form SD.AirlineRatings do I have in SD.Airlines, I did this :

SELECT b.Name AS Airline FROM SD.Airlines b
LEFT JOIN SD.AirlineRatings a ON a.AirlineName = b.Name
WHERE a.AirlineName IS NOT NULL;

Works fine, showed me 249/405 records. Now... If I need to compare those 249 records towards SD.AirlineRatings and check which ones I don't have.

I bet answer is simple but I don't know SQL that much.

Thanks

1 Answer 1

2

If you want records in AirLines ratings that are also in Airlines, then I would recommend EXISTS or IN:

select a.*
from sd.Airlines a
where exists (select 1 from sd.AirlineRatings ar where ar.AirlineName = a.Name);

If you want unrated airlines:

select a.*
from sd.Airlines a
where not exists (select 1 from sd.AirlineRatings ar where ar.AirlineName = a.Name);

And, if you want ratings on airlines that don't exist, you would swap the two tables in the query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.