I have a issue with a table that has missing data from some rows, I need to copy the Artist column from another row that matches on title
Plays | Title | Artist
------+--------------------------+----------------
107 | Superstition | Stevie Wonder
96 | Superstition | NULL
158 | Patience | Guns n Roses
9 | Patience | NULL
112 | Promised You A Miracle | Simple Minds
99 | Promised You A Miracle | NULL
159 | Baker Street | Gerry Rafferty
132 | Baker Street | NULL
I have read a bunch of other questions on SO's that has landed me with this UPDATE statement:
UPDATE MetaDataTable
SET Artist = (SELECT TOP 1 Artist FROM MetaDataTable t
WHERE (Title = t.Title) AND t.Artist IS NOT NULL)
WHERE Artist IS NULL
What this end up with is the TOP 1 Artist being copied to all NULL Artist columns, not the Artist with the matching Title.
Plays | Title | Artist
------+--------------------------+----------------
107 | Superstition | Stevie Wonder
96 | Superstition | Stevie Wonder
158 | Patience | Guns n Roses
9 | Patience | Stevie Wonder
112 | Promised You A Miracle | Simple Minds
99 | Promised You A Miracle | Stevie Wonder
159 | Baker Street | Gerry Rafferty
132 | Baker Street | Stevie Wonder
What I would like is this:
Plays | Title | Artist
------+--------------------------+----------------
107 | Superstition | Stevie Wonder
96 | Superstition | Stevie Wonder
158 | Patience | Guns n Roses
9 | Patience | Guns n Roses
112 | Promised You A Miracle | Simple Minds
99 | Promised You A Miracle | Simple Minds
159 | Baker Street | Gerry Rafferty
132 | Baker Street | Gerry Rafferty
The rows with NULL Artist could be anywhere in the table and are not strictly below a complete row with the same Title.
Thanks!