Joining two queries

TIbbs

Registered User.
Local time
Today, 13:46
Joined
Jun 3, 2008
Messages
60
I have two queries:

Query 1- shows all customers that have and do not have any orders in the system.

Query 2-All product data that have or have not been assigned to an order.

They both have the same fields. But not every product is assigned to an order and not every customers places an order. That is the reason why I ask about the join.

I need to create reports that show the sales orders for both products and customers. Ranging from total sales to customer sales.
Would it be more efficient to use a Union query to join both queries and then create the parameter queries from this main query?
Or should I base my reports by product and by customer separately.
 
I don't understand how customer data and product data can consist of the same fields.

You would use an outer join to include all of the data from one table and any from the other table that matches. You could do this both ways and then union them together. If you use UNION and not UNION ALL, then any duplicated records will be eliminated.
 
My mistake, the queries return the same fields, but one in relation to customers and the other in relation to products.
It's two queries one that returns all customers that have and have not any invoice orders
The other query returns all products that have or not been assigned to any invoice orders.
Products and customers are joined by an Invoice Item collection class.
We need to keep track of which products are doing worse than others and we need to find out what customers are buying.
I have to do a left join to get all customer with and without orders and a left join to get all products with and without orders.
I need then to run reports for total product sales and reports for total customer purchases and past buying history.
I was wondering if I did an UNION I would get all customers and products that are and are not assigned to invoices and then a run the other queries from this table.
Or should I just run them as separate queries anyway.
 
I don't know enough to have a clue which is the most efficient way of doing this. If it works, it works!
 

Users who are viewing this thread

Back
Top Bottom