Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL: Extracting data from three tables

I am looking to show in ascending order the NameOfMovie that occur most often from the MoviePlaylist where the Playlist Genre_Name = TV Shows or 90’s movie.

The three tables are setup as follows:

   Movie => MovieID, NameOfMovie
   PlaylistMovie => MovieID, PlaylistID
   Playlist => PlaylistID, Genre_Name

I have tried the following but it does not work:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Select movie.MovieId, movie.NameOfMovie, playlisttrack.PlaylistId
From playlisttrack
Inner Join movie on movie.MovieId = playlistMovie.MovieId
Inner Join playlist on playlistMovie.playlistId = playlist.playlistId
where playlistMovie.PlaylistId = 'TV Shows' or playlistMovie.PlaylistId = '90s Movie'
group by Movie.Name;

>Solution :

Like this?

select track.Name, 
       count(*) track_count
  from playlisttrack
 inner Join track on track.TrackId = playlisttrack.TrackId
 inner Join playlist on playlisttrack.playlistId = playlist.playlistId
where playlisttrack.PlaylistId = 3 or playlisttrack.PlaylistId = 5
group by track.Name
order by 2 desc;

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading