138k views
4 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 playlist_track_names AS SELECT playlist.name as playlist_name, track.name as track_name FROM playlist INNER JOIN playlist_track ON playlist.playlist_id = playlist_track.playlist_id INNER JOIN track ON playlist_track.track_id = track.track_id;
SELECT * FROM playlist_track_names ORDER BY playlist_name DESC, track_name DESC;

1 Answer

4 votes

Final answer:

To retrieve playlist names and track names in descending order from the 'playlist_track_names' view, use the SQL 'ORDER BY' clause, sorting first by playlist_name then by track_name both in descending order.

Step-by-step explanation:

To query playlist names and track names in descending order from the playlist_track_names view that has been created, you can use the SQL ORDER BY clause. Here is how you can write the query:

SELECT playlist_name, track_name FROM playlist_track_names ORDER BY playlist_name DESC, track_name DESC;

This SQL statement will return the results sorted by playlist_name in descending order first, and then by track_name in descending order within each playlist grouping, ensuring that the names are sorted from Z to A. This is a common pattern when dealing with sorting in SQL, allowing for a clear hierarchical organization of the ordered data.

User Legolas
by
7.5k points