Skip to content

Instantly share code, notes, and snippets.

@andrewkowalik
Created June 4, 2013 00:51
Show Gist options
  • Save andrewkowalik/5702775 to your computer and use it in GitHub Desktop.
Save andrewkowalik/5702775 to your computer and use it in GitHub Desktop.
SQLZoo SELECT from Nobel Tutorial #8 solution using single join, no sub-query
SELECT DISTINCT a.yr
FROM nobel a
LEFT OUTER JOIN nobel b
ON a.yr=b.yr
AND b.subject NOT IN ('Economics','Literature','Medicine','Peace','Physics')
WHERE b.subject IS NULL
AND a.subject = 'Physics'
@hsukang
Copy link

hsukang commented Feb 2, 2015

Your query was really very good. But, how did you know the subjects without any query?
So, I think it would be better to modify your query as follows:

SELECT DISTINCT n1.yr
FROM nobel n1 LEFT OUTER JOIN nobel n2 ON (n1.yr = n2.yr AND n2.subject = 'Chemistry')
WHERE n1.subject = 'Physics' AND n2.subject IS NULL  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment