我需要删除所有未记录特定类型的艺术家;即爵士乐。我制定了以下查询:
select * from artists ar
join titles ti on ti.artistid = ar.artistid
where ti.genre != 'jazz';
我相信这些数据是没有录制爵士乐冠军的艺术家。另外,我不确定删除这些数据的命令。
我的艺术家表格如下:
Artists
-------
ArtistID, ArtistName, City, Region
我的标题表如下:
Titles
------
TitleID, ArtistID, Title, StudioID, Genre
我也尝试过:
delete artists
from artists ar
inner join
titles ti on ti.artistid = ar.artistid where ti.genre != 'jazz';
SQL查询引擎抛出一个错误说明:ERROR 1109(42S02):MULTI DELETE中未知的表'artists'
答案 0 :(得分:1)
您的第一个查询应该是:
SELECT a.*
FROM artists a
LEFT JOIN titles t ON t.artistid = a.artistid AND t.genre = 'jazz'
WHERE t.artistid IS NULL
相应的DELETE
是:
DELETE a.*
FROM artists a
LEFT JOIN titles t ON t.artistid = a.artistid AND t.genre = 'jazz'
WHERE t.artistid IS NULL