1

I have:

DELETE FROM songs 
WHERE songs.id_album = album.id 
AND album.id_band =16`

Error: #1054 - Unbekanntes Tabellenfeld 'album.id' in where clause.

Table album exists, field id too, 100%.

Where is error?

Thank you.

3

You can't use the album table because it isn't actually included in the query. (in the FROM clause). You need to do this instead:

DELETE songs.*
FROM songs
  JOIN album 
    ON album.id = songs.id_album
 WHERE album.id_band = 16

See the section titled Multi-Table Deletes in the documentation for DELETE.

Alternatively, you could use WHERE EXISTS:

DELETE FROM songs
 WHERE EXISTS (SELECT * 
                 FROM album 
                WHERE id_band = 16 
                  AND id = songs.id_album)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.