I got a challenge from school to optimise this query (this is theoretical question)
Challenge :
SELECT
n.node_id,
MIN(LEAST(n.date,ec.date)) date
FROM
n, ec
WHERE
(n.node_id = ec.node_id_from OR n.node_id = ec.node_id_to)
AND n.date - ec.date > 0
GROUP BY
n.node_id;
I make some effort to optimise this query and need to share with guys
SELECT
n.node_id, LEAST (n.date, ec.date) date
FROM
n
INNER JOIN
ec ON (n.node_id = ec.node_id_from OR n.node_id = ec.node_id_to)
WHERE
n.date - ec.date > 0
What I have done: I removed the min function and group by because least function only return least value from string.
Secondly I added the inner join with this query.
Is my solution fine or you have some more better option?