Why do you need to name the subquery?


#1

Why do you need to name avg(a.sale_price) instead of just avg(sale_price)?

id on the other hand is not named as a.id

why?

Also, the code runs without doing this and even without naming the subquery

SELECT id, avg(a.sale_price) FROM (
SELECT id, sale_price FROM order_items
UNION ALL
SELECT id, sale_price FROM order_items_historic) AS a
GROUP BY 1;


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.