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
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
ralmada
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo