I have two (simplified) tables in a database.
Table: queuelist
'songID', 'lastplayed'
'7376', '12/01/2013'
'9322', '16/08/2012'
Table: songlist
'ID', 'artist'
'7376', 'Michael Jackson'
'2345', 'Nirvana'
'songID'
and 'ID'
are the same fields.
I'm given 'Michael Jackson'
as an input and I want to delete the first row in 'queuelist'
based on looking up 'ID'
as the common field. I'm a MYSQL noob and have been trying examples but so far don't quite follow the syntax.
So far I have this...
DELETE S.songID
FROM queuelist Q,
(
JOIN songlist S
ON Q.songID = S.ID
)
WHERE S.artist = 'Michael Jackson'
You should use a sub-query
in the WHERE clause
rather than using JOIN
.
DELETE FROM `queuelist`
WHERE `songID` IN (SELECT `S`.`ID`
FROM `songlist` `S`
WHERE `S`.`artist` = 'Michael Jackson')
This will be the resulted data:
Table: queuelist
'songID', 'lastplayed'
'9322', '16/08/2012'
Table: songlist
'ID', 'artist'
'7376', 'Michael Jackson'
'2345', 'Nirvana'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments