I'm trying to make a SELECT
but I can´t test it on SQL management studio because it's always giving me errors.
I can´t find the error, any help is appreciated, thanks !
SELECT [Order].CustomOrderNumber, [Order].OrderTotal, [Order].OrderDiscount, [DiscountUsageHistory].DiscountID, [DiscountUsageHistory].OrderID, [Discount].ID, [Discount].Name
FROM (([Order] , [Discount] , [DiscountUsageHistory]
INNER JOIN [DiscountUsageHistory] ON [Order].CustomOrderNumber = [DiscountUsageHistory].OrderID)
INNER JOIN [Discount] ON [DiscountUsageHistory].DiscountID = [Discount].ID)
WHERE OrderDiscount > 0
Your query has a strange mixture of implicit joins and explicit joins. You should never use implicit joins, ever.
A correct query structure would be something like this:
SELECT [Order].CustomOrderNumber,
[Order].OrderTotal,
[Order].OrderDiscount,
[DiscountUsageHistory].DiscountID,
[DiscountUsageHistory].OrderID,
[Discount].ID,
[Discount].Name
FROM [Order]
INNER JOIN [DiscountUsageHistory] ON [Order].CustomOrderNumber = [DiscountUsageHistory].OrderID
INNER JOIN [Discount] ON [DiscountUsageHistory].DiscountID = [Discount].ID
WHERE OrderDiscount > 0
If your relations are correct -
You had multiple tables linked to from
.
The inner join makes those relations for you.
SELECT [Order].CustomOrderNumber, [Order].OrderTotal, [Order].OrderDiscount, [DiscountUsageHistory].DiscountID, [DiscountUsageHistory].OrderID, [Discount].ID, [Discount].Name
FROM [Order]
INNER JOIN [DiscountUsageHistory] ON [Order].CustomOrderNumber = [DiscountUsageHistory].OrderID
INNER JOIN [Discount] ON [DiscountUsageHistory].DiscountID = [Discount].ID
WHERE [Order].OrderDiscount > 0
Try:
SELECT
ORD.CustomOrderNumber,
ORD.OrderTotal,
ORD.OrderDiscount,
DISUH.DiscountID,
DISUH.OrderID,
DIS.ID,
DIS.[Name]
FROM
[Order] AS ORD
INNER JOIN
[DiscountUsageHistory] AS DISHU ON ORD.CustomOrderNumber = DISHU.OrderID
INNER JOIN
[Discount] AS DIS ON DISHU.DiscountID = DIS.ID
WHERE ORD.OrderDiscount > 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.