Order and orderDetail combined

Peter Nordberg
Peter Nordberg used Ask the Experts™
on
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(paymentTypeID, paymentType)

I've done a query like this:
SELECT        ordersAdminFeeDetail.orderID, orders.orderDate, customer.FirstName + ' ' + customer.Lastname AS Name, orders.feePercentage / 100 AS p,
                         ordersAdminFeeDetail.dInvoiceID, 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.orderID = 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.paymentTypeID
GROUP BY ordersAdminFeeDetail.orderID, orders.orderDate, ordersAdminFeeDetail.dInvoiceID, customer.FirstName, customer.Lastname, orders.feePercentage,
                         bklPaymentType.PaymentType, orders.handlingFee, orders.shipmentFee, orderDetail.quantity, orderDetail.taxValue
ORDER BY ordersAdminFeeDetail.orderID

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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
check this:
SELECT  ordersAdminFeeDetail.orderID, 
	orders.orderDate, 
	customer.FirstName + ' ' + customer.Lastname AS Name, 
	orders.feePercentage / 100 AS p, 
	ordersAdminFeeDetail.dInvoiceID, 
	bklPaymentType.PaymentType, 
	SUM(orderDetail.price) AS pris, 
         SUM(orderDetail.Quantity) as sumquantity,
	SUM((orderDetail.price * orderDetail.quantity) * (orderDetail.taxValue / 100)) AS tax
FROM            ordersAdminFeeDetail 
INNER JOIN orders ON ordersAdminFeeDetail.orderID = 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.paymentTypeID

GROUP BY ordersAdminFeeDetail.orderID, 
	orders.orderDate, 
	ordersAdminFeeDetail.dInvoiceID, 
	customer.FirstName, 
	customer.Lastname, 
	orders.feePercentage, 
        bklPaymentType.PaymentType, 
	orders.handlingFee, 
	orders.shipmentFee, 

ORDER BY ordersAdminFeeDetail.orderID

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial