71.5k views
0 votes
Given the following view that has been created, how would you query the playlist names and track names both in descending order? CREATE VIEW PlaylistTrackNames AS

SELECT
Playlist.Name AS PlaylistName,
Track.Name AS TrackName
FROM Playlist
INNER JOIN PlaylistTrack ON Playlist.PlaylistID = PlaylistTrack.PlaylistID;
a) SELECT * FROM PlaylistTrackNames ORDER BY PlaylistName DESC, TrackName DESC;

b) SELECT PlaylistName, TrackName FROM PlaylistTrackNames ORDER BY PlaylistName DESC, TrackName DESC;

c) SELECT * FROM PlaylistTrackNames ORDER BY PlaylistName, TrackName DESC;

d) SELECT PlaylistName, TrackName FROM PlaylistTrackNames ORDER BY PlaylistName, TrackName DESC;

1 Answer

7 votes

Final answer:

To order both playlist names and track names in descending order, the correct SQL query would be option (b): SELECT PlaylistName, TrackName FROM PlaylistTrackNames ORDER BY PlaylistName DESC, TrackName DESC.

Step-by-step explanation:

To query the playlist names and track names both in descending order from the created view PlaylistTrackNames, you should select the relevant columns and add an ORDER BY clause that specifies both columns in descending order. The correct SQL statement for this would be:

SELECT PlaylistName, TrackName FROM PlaylistTrackNames ORDER BY PlaylistName DESC, TrackName DESC;

This corresponds to option (b) and ensures that the results returned will first be sorted by PlaylistName in descending order and then by TrackName in descending order within each playlist grouping.

User Jonas Anseeuw
by
7.9k points