Peter Nordberg
asked on
Order and orderDetail combined
Hi,
I would like to combine seceral tables in a query. The tables are as follows:
orders (orderID, orderDate, feePercentage, customerID, paymentTypeID)
orderDetail (orderID, price, taxValue, quantity)
customers(customerID, FirstName, LastName)
orderAdminFeeDetail (orderID, dInvoiceID)
bklPaymentType(paymentType ID, paymentType)
I've done a query like this:
SELECT ordersAdminFeeDetail.order ID, orders.orderDate, customer.FirstName + ' ' + customer.Lastname AS Name, orders.feePercentage / 100 AS p,
ordersAdminFeeDetail.dInvo iceID, bklPaymentType.PaymentType , SUM(orderDetail.price) AS pris,
orderDetail.quantity, SUM((orderDetail.price * orderDetail.quantity) * (orderDetail.taxValue / 100)) AS tax
FROM ordersAdminFeeDetail INNER JOIN
orders ON ordersAdminFeeDetail.order ID = orders.orderID INNER JOIN
customer ON orders.customerID = customer.customerID INNER JOIN
orderDetail ON orders.orderID = orderDetail.orderID INNER JOIN
bklPaymentType ON orders.PaymentTypeID = bklPaymentType.paymentType ID
GROUP BY ordersAdminFeeDetail.order ID, orders.orderDate, ordersAdminFeeDetail.dInvo iceID, customer.FirstName, customer.Lastname, orders.feePercentage,
bklPaymentType.PaymentType , orders.handlingFee, orders.shipmentFee, orderDetail.quantity, orderDetail.taxValue
ORDER BY ordersAdminFeeDetail.order ID
The problem with that query is that when orderDetail has more than one items per orderID the orderID shows up more than one time in the resultset. I would like to have the resultset lso that each orderID only shows up once with all the data that's specified above in that one row. How can I accomplish this?
Peter
I would like to combine seceral tables in a query. The tables are as follows:
orders (orderID, orderDate, feePercentage, customerID, paymentTypeID)
orderDetail (orderID, price, taxValue, quantity)
customers(customerID, FirstName, LastName)
orderAdminFeeDetail (orderID, dInvoiceID)
bklPaymentType(paymentType
I've done a query like this:
SELECT ordersAdminFeeDetail.order
ordersAdminFeeDetail.dInvo
orderDetail.quantity, SUM((orderDetail.price * orderDetail.quantity) * (orderDetail.taxValue / 100)) AS tax
FROM ordersAdminFeeDetail INNER JOIN
orders ON ordersAdminFeeDetail.order
customer ON orders.customerID = customer.customerID INNER JOIN
orderDetail ON orders.orderID = orderDetail.orderID INNER JOIN
bklPaymentType ON orders.PaymentTypeID = bklPaymentType.paymentType
GROUP BY ordersAdminFeeDetail.order
bklPaymentType.PaymentType
ORDER BY ordersAdminFeeDetail.order
The problem with that query is that when orderDetail has more than one items per orderID the orderID shows up more than one time in the resultset. I would like to have the resultset lso that each orderID only shows up once with all the data that's specified above in that one row. How can I accomplish this?
Peter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.