SELECT *
FROM program AS p
INNER JOIN agent AS a ON p.ag_id = a.ag_id
INNER JOIN nation AS n ON p.n_id = n.n_id
WHERE p.n_id ='$na_id'
order by ag_name
SELECT *
FROM program AS p
INNER JOIN agent AS a ON p.ag_id = a.ag_id
INNER JOIN nation AS n ON p.n_id = n.n_id
WHERE p.n_id ='$na_id'
order by ag_name and code