We help IT Professionals succeed at work.
Get Started

Order and orderDetail combined

373 Views
Last Modified: 2012-05-11
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
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE