SELECT CONCAT( 'A ', GROUP_CONCAT(DISTINCT(ib.ediBotanic) SEPARATOR ', '), CHAR(13,10), CHAR(13,10), 'B ES17462130', CHAR(13,10), CHAR(13,10), 'C ', GROUP_CONCAT(DISTINCT(t.id) SEPARATOR ', '), CHAR(13,10), CHAR(13,10), 'D ES' ) phytosanitary FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemCategory ic ON ic.id = it.categoryFk JOIN vn.itemBotanicalWithGenus ib ON ib.itemfk = i.id WHERE t.refFk = # AND ic.`code` = 'plant' AND ib.ediBotanic IS NOT NULL ORDER BY ib.ediBotanic