Learn

Great job! What if we wanted to allow duplicate values? We can do this by using the ALL keyword with UNION, with the following syntax:

SELECT column_name(s) FROM table1 UNION ALL SELECT column_name(s) FROM table2;

In our ecommerce store, if we learned that we had records from historic order items in an additional table, we could use the following query to combine the tables for a complete analysis of sale price:

SELECT id, sale_price FROM order_items UNION ALL SELECT id, sale_price FROM order_items_historic;

Then we can perform an analysis on top of the combined result set, like finding the total count of order items.

SELECT count(*) FROM ( SELECT id, sale_price FROM order_items UNION ALL SELECT id, sale_price FROM order_items_historic) as a;

Instructions

1.

Using the same pattern, utilize a subquery to find the average sale price over both order_items and order_items_historic tables.

Sign up to start coding

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Already have an account?