SELECT * FROM `artistname` join (select artistnameid from artistname where `subartistnameid` is NULL) a where a.artistnameid = `subartistnameid`