0

EER Diagram

enter image description here

Question

List the customer number, customer name (first and last), order number, order date, employee number, employee name (first and last), product number, product name, and order cost (product quantity * product unit price) for telephone orders (A telephone order has an associated employee) placed on January 23, 2007 and the order cost exceeds $150. Order the result by the order cost in descending order.

My Code

SELECT
    Customer.CustNo,
    Customer.FirstName,
    Customer.LastName,
    `Order`.OrderNo,
    `Order`.OrderDate,
    Employee.EmpNo,
    Employee.FirstName,
    Employee.LastName,
    Product.ProdNo,
    Product.ProdName,
    CONCAT('$', ProductInOrder.Qty * SUBSTRING(Product.Price, 2)) AS `Order Cost`
From Customer, `Order`, Employee, Product, ProductInOrder
WHERE
    `Order`.Employee_EmpNo IS NOT NULL                          AND
    STR_TO_DATE(`Order`.OrderDate, '%m/%d/%Y') = '2007-1-23'    AND
    ProductInOrder.Qty * SUBSTRING(Product.Price, 2) > 150
ORDER BY `Order Cost` DESC;

Result

enter image description here

14:57:29 SELECT Customer.CustNo, Customer.FirstName, Customer.LastName, Order.OrderNo, Order.OrderDate, Employee.EmpNo, Employee.FirstName, Employee.LastName, Product.ProdNo, Product.ProdName, CONCAT('$', ProductInOrder.Qty * SUBSTRING(Product.Price, 2)) AS Order Cost From Customer, Order, Employee, Product, ProductInOrder WHERE Order.Employee_EmpNo IS NOT NULL AND STR_TO_DATE(Order.OrderDate, '%m/%d/%Y') = '2007-1-23' AND ProductInOrder.Qty * SUBSTRING(Product.Price, 2) > 150 ORDER BY Order Cost DESC LIMIT 0, 1000 1000 row(s) returned 0.290 sec / 0.011 sec


My Question

I think there is something wrong with the code From Customer, Order, Employee, Product, ProductInOrder. How to join all the tables together? If I use INNER JOIN, it will be more complicated.


Thank you for your help.

1

It says like syntax error, which you missed the ,

SELECT
    Customer.CustNo,
    Customer.FirstName,
    Customer.LastName,
    `Order`.OrderNo,
    `Order`.OrderDate,
    Employee.EmpNo,
    Employee.FirstName,
    Employee.LastName,
    Product.ProdNo,
    Product.ProdName,
    CONCAT('$', ProductInOrder.Qty * SUBSTRING(Product.Price, 2)) AS `Order Cost`
From Customer, `Order`, Employee, Product, ProductInOrder
WHERE
    `Order`.Employee_EmpNo IS NOT NULL                          AND
    STR_TO_DATE(`Order`.OrderDate, '%m/%d/%Y') = '2007-1-23'    AND
    `Order`.Cost > 150
ORDER BY `Order`.Cost DESC;
| improve this answer | |
  • Codes updated but I problem is still here. =[ – Casper Oct 9 '14 at 6:48
  • Still its a syntax error only, updated – senK Oct 9 '14 at 6:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.