nu es varu teikt, ka sql esmu bikucīt izkodis ;) man ir sekss ar subSELECTiem un stored procedures.
SELECT repertuars_getConductors(repertuars.id, repertuars.lang) AS conductors_list
FROM repertuars
WHERE repertuars.date_on = (SELECT MIN(r.date_on)
FROM repertuars AS r
WHERE r.iestudejums_id = repertuars.iestudejums_id AND
r.deleted = '0' AND r.enabled = '1' AND
ABS(DATEDIFF(NOW(), r.date_on)) = (SELECT MIN(ABS(DATEDIFF(NOW(), r2.date_on)))
FROM repertuars AS r2
WHERE r2.iestudejums_id = r.iestudejums_id AND
r2.deleted = '0' AND r2.enabled = '1')
...