Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just remove the distinct on the column you are counting. </p> <pre><code>SELECT actorinfo.actorID, actorinfo.firstname, actorinfo.lastname, COUNT(actorinfo.actorID) as total FROM ActorInfo as actorinfo LEFT OUTER JOIN CastInfo as castinfo ON actorinfo.actorID= castinfo.actorID LEFT OUTER JOIN GenreInfo as genreinfo ON castinfo.mvID = genreinfo.mvID WHERE genreinfo.genre = 'Drama' GROUP BY actorinfo.actorID ORDER BY total ASC; </code></pre> <p><a href="http://sqlfiddle.com/#!2/29364/6" rel="nofollow">http://sqlfiddle.com/#!2/29364/6</a></p> <p>You don't want to count the distinct occurrences of the id value in your group, since the id you are grouping on will obviously always have the same value within the group. Alternatively you could group on the id of genreinfo and id of actor and count all records within group, a bit more self explanatory.</p> <pre><code>SELECT actorinfo.actorID, actorinfo.firstname, actorinfo.lastname, COUNT(*) as total FROM ActorInfo as actorinfo LEFT OUTER JOIN CastInfo as castinfo ON actorinfo.actorID= castinfo.actorID LEFT OUTER JOIN GenreInfo as genreinfo ON castinfo.mvID = genreinfo.mvID WHERE genreinfo.genre = 'Drama' GROUP BY genreinfo.mvId,actorinfo.actorID ORDER BY total ASC; </code></pre> <p>If you have the information related to specific movie , i suppose that would go to the castinfo where the relationship between actor and genre is held. In that case you should do the following to avoid repetition,</p> <pre><code>SELECT actorinfo.actorID, actorinfo.firstname, actorinfo.lastname, COUNT(DISTINCT castinfo.movie_name) as total FROM ActorInfo as actorinfo LEFT OUTER JOIN CastInfo as castinfo ON actorinfo.actorID= castinfo.actorID LEFT OUTER JOIN GenreInfo as genreinfo ON castinfo.mvID = genreinfo.mvID WHERE genreinfo.genre = 'Drama' GROUP BY genreinfo.mvId,actorinfo.actorID ORDER BY total ASC; </code></pre> <p><a href="http://sqlfiddle.com/#!2/aa4363/1" rel="nofollow">http://sqlfiddle.com/#!2/aa4363/1</a></p>
    singulars
    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.
 

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