Skip to content Skip to sidebar Skip to footer

Cartesian Products And Selects In The From Clause

I need to use a select in the from clause but I keep getting an Cartesian product. select customer.customer_name ,orders.order_date ,order_line.num_ordered ,order_line.quoted_pric

Solution 1:

The reason for Cartesian product is, you didn't join the sub-select with orders or Part table.

First of all you don't need that sub-select

SELECT customer.customer_name, 
       orders.order_date, 
       order_line.num_ordered, 
       order_line.quoted_price, 
       part.descript, 
       order_line.num_ordered * part.price AS amt_billed 
FROM   customer 
       JOIN orders 
         ON customer.customer_num = orders.customer_num 
       JOIN order_line 
         ON orders.order_num = order_line.order_num 
       JOIN part 
         ON order_line.part_num = part.part_num; 

Post a Comment for "Cartesian Products And Selects In The From Clause"