I'm a beginner in SQL however I have two tables one LibraryTable where I have list of songs, and another table called Playlist, I'm using netbeans to program a prototype jukebox, and I can add songs from the Library to my playlist, and I can increment playcount of all the song that where added to the playlist, however both LibraryTable and Playlist have a column called playcount, I want know how I would go about updating the playcount column in LibraryTable with the the playcount column in my Playlist table.
Asked
Active
Viewed 1,422 times
1
-
Is this MySQL or SQL Server? And what have you tried so far? Please share some code. – Mureinik Feb 14 '14 at 14:27
-
update LibraryTable set playcount =p.playcount from LibraryTable LT inner join Playlist P on lt.id=p.id – KumarHarsh Feb 14 '14 at 14:29
1 Answers
2
You can do joins in UPDATE
statements.
UPDATE L
SET L.Playcount = P.Playcount
FROM Playlist P
INNER JOIN LibraryTable L
ON P.SongID = L.SongID

TTeeple
- 2,913
- 1
- 13
- 22
-
You are brilliant thank you worked perfectly, except i just had to change SongID to just ID lol, but thanks for everyones help. – user3012997 Feb 14 '14 at 14:41