Link to home
Start Free TrialLog in
Avatar of Peter Nordberg
Peter NordbergFlag for Sweden

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(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
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial