MySQL select complementary pairs on particular values
Try changing your JOIN statement as follows:

     join main b on a.accession &lt; b.accession AND a.folder= b.folder


This should include a.accession = "Z1" and b.accession = "Z2", but exclude a.accession = "Z2" and b.accession = "Z1".