What's causing a difference in output?

Lesson 464, Intermediate Joins in SQL, Combining Multiple Joins with Subqueries

Screen Link:

My Code:

SELECT
    ta.album_title album,
    ta.artist_name artist,
    COUNT(*) tracks_purchased
FROM invoice_line il
INNER JOIN (
            SELECT
                t.track_id,
                al.title album_title,
                ar.name artist_name
            FROM track t
            INNER JOIN album al ON al.album_id = t.album_id
            INNER JOIN artist ar ON ar.artist_id = al.artist_id
           ) ta
           ON ta.track_id = il.track_id
GROUP BY 1, 2
ORDER BY 3 DESC LIMIT 5;

-- SELECT
--     ta.title album,
--     ta.name artist,
--     COUNT(*) track_purchased
--     FROM invoice_line il
-- INNER JOIN (
--     SELECT
--         t.track_id,
--         al.title,
--         ar.name
--     FROM track t
--     INNER JOIN album al ON al.album_id = t.album_id
--     INNER JOIN artist ar ON ar.artist_id = al.artist_id
-- ) ta
-- ON ta.track_id = il.track_id
-- GROUP BY 1, 2
-- ORDER BY 3 DESC
-- LIMIT 5
-- ;

What I expected to happen:
I would think these two SQL queries would have the same results but they don’t.

What actually happened:
The outputted table is off by one line

Replace this line with the output/error

Should these queries have the same output or am I missing something?

Hi, @kylejdini

They both have the exact same output on my end:

Please try to refresh the page and run each query separated again. If the outputs are still not the same, please share them.

Hi,

Looks like the issue was that I put ‘track_purchased’ instead of ‘tracks_purchased’, whoops!
I was wondering why it wouldn’t accept my answer! Thank you for the reply!

2 Likes