Let me rewrite your queries without any sinifical changes:
Query 1
SELECT i.invoice_id,
i.total_price
FROM invoice INNER JOIN (
SELECT invoice_id,
sum(price) AS total_price
FROM orders
GROUP BY
invoice_id
) AS i
ON i.invoice_id = invoice.invoice_id;
Query 2:
SELECT invoice.invoice_id,
i.total_price
FROM invoice INNER JOIN (
SELECT invoice_id,
sum(price) AS total_price
FROM orders
GROUP BY
invoice_id
) AS i
ON i.invoice_id = invoice.invoice_id;
things I changed:
- order of
JOIN
(which doesn't matter, since it isINNER
) - table alias (
orders
toi
, and I really don't understand, why you wanted to name it differently)
Now, it is obvious, that the only difference between them - the first argument in the main SELECT
. Your question could have made sence (if there was index on one column and wasn't on the other, and, dependant on the query, you would not always have used both orders.invoice_id
and invoice.invoice_id
), but since you already retrieving the both column for INNER JOIN
it doesn't.
Futhermore, these queries are redundant. As already been mentioned by @valex, your query (actually - both of them) could (and must) be simplified to this:
SELECT invoice_id,
sum(price) AS total_price
FROM orders
GROUP BY
invoice_id;
So, no, there is no differnce in perfomance. And, surely, there is no difference in resultset.
Also, I'd like you to know, that you can always use EXPLAIN
for perfomance questions.