JOIN...
PHP kôd:
SELECT t1.rastojanje, t2.grad AS grad_1, t3.grad AS grad_2
FROM tabela2 AS t1
LEFT JOIN tabela1 AS t2 ON t1.grad_id1 = t2.id
LEFT JOIN tabela1 AS t3 ON t1.grad_id2 = t3.id
Subselect...
PHP kôd:
SELECT tabela2.rastojanje,
(SELECT tabela1.grad FROM tabela1 WHERE tabela1.id = tabela2.grad_id1) AS grad_1,
(SELECT tabela1.grad FROM tabela1 WHERE tabela1.id = tabela2.grad_id2) AS grad_2
FROM tabela2;
Koristi JOIN jer je dosta brži...