I would like to create a sql query that returns results together for 2 different queries. For example, I’d like to have results in the form of:
Product Name, avg(price), min(price), max(price), avg(order), min(order), max(order)
At the moment I have 2 sql queries of the form:
select
product.name, order.id, avg(price), min(price), max(price)
from
product, order
where
product.name = order.product_name and product.name = 'price'
group by
product.name, order.id
select
product.name, order.id, avg(order), min(order), max(order)
from
product, order
where
product.name = order.product_name and product.name = 'order'
group by
product.name, order.id
Some products have a price and an order, others have only a price, and others have only and order. How do I write a query that will display all the results and join those that have both an order and a price and display those that have both as i row?
I think what you need is a full outer join since rows could be in either one table or the other or both: