Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're on the right track. I'd recommend looking at <a href="https://en.wikipedia.org/wiki/Join_%28SQL%29" rel="nofollow"><code>JOIN</code></a>s.</p> <p>I've provided a step-by-step answer on how to obtain the desired results. If you just want the final query, go down to step 5 and pick the one appropriate for your DBMS.</p> <h2>1: Selecting all comedy movie IDs:</h2> <pre><code>SELECT mvid FROM GenreInfo WHERE genre = 'Comedy'; </code></pre> <h2>2: Selecting the directorIDs of those movies</h2> <pre><code>SELECT directorID FROM DirectInfo JOIN GenreInfo ON DirectInfo.mvID = GenreInfo.mvID WHERE genre = 'Comedy'; </code></pre> <h2>3: Selecting the director name of those directors.</h2> <pre><code>SELECT firstname FROM DirectorInfo JOIN DirectInfo ON DirectorInfo.directorID = DirectInfo.directorID JOIN GenreInfo ON DirectInfo.mvID = GenreInfo.mvID WHERE genre = 'Comedy'; </code></pre> <h2>4: Grouping that query by director to get number of movies:</h2> <pre><code>SELECT firstname, COUNT(*) AS NumberOfMovies FROM DirectorInfo JOIN DirectInfo ON DirectorInfo.directorID = DirectInfo.directorID JOIN GenreInfo ON DirectInfo.mvID = GenreInfo.mvID WHERE genre = 'Comedy' GROUP BY DirectorInfo.directorID; </code></pre> <h2>5: Sort the results and get only the first one:</h2> <pre><code>SELECT firstname, COUNT(*) AS NumberOfMovies FROM DirectorInfo JOIN DirectInfo ON DirectorInfo.directorID = DirectInfo.directorID JOIN GenreInfo ON DirectInfo.mvID = GenreInfo.mvID WHERE genre = 'Comedy' GROUP BY DirectorInfo.directorID ORDER BY NumberOfMovies LIMIT 1; </code></pre> <p>If you're using SQL server, use <code>TOP</code> instead:</p> <pre><code>SELECT TOP 1 firstname, COUNT(*) AS NumberOfMovies FROM DirectorInfo JOIN DirectInfo ON DirectorInfo.directorID = DirectInfo.directorID JOIN GenreInfo ON DirectInfo.mvID = GenreInfo.mvID WHERE genre = 'Comedy' GROUP BY DirectorInfo.directorID ORDER BY NumberOfMovies; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload