But some of the files don't have data in the last two tags: tracknumber and composer. Is there a way to ignore these fields if they are blank. A bit like [%tracknumber%] ?
where tracknumber is not null and composer is not null
This will remove the tracks from the matching process entirely.
Generally, SQL treats a missing value as unknown, so when comparing one unknown to any other value (including another unknown) the result is also unknown (not true). In your example, if two tracks matched on all the tags except one (or both) tracks had missing track numbers the join at the bottom of your step (and a.tracknumber = b.tracknumber) would exclude those matches from the result set.
If all you're asking is to bring back matches where BOTH matching tracks are missing tracknumber or composer then the following sql should work (because it replaces the missing/unknown value with #).
select a.path, a.artist, a.title, a.album, a.length, a.tracknumber, a.composer
from mediaLibrary a
inner join
(select artist, title, album, length, coalesce(tracknumber,'#') as tracknumber, coalesce(composer,'#') as composer
from mediaLibrary
group by 1, 2, 3, 4, 5, 6
having count(*)>1
) b on ( a.artist = b.artist
and a.title = b.title
and a.album = b.album
and a.length = b.length
and coalesce(a.tracknumber,'#') = b.tracknumber
and coalesce(a.composer,'#') = b.composer)
order by a.path
This however won't match tracks where one has a tracknumber but the other doesn't, and I'm not sure there's a way around that.