Search code examples
sqljoininner-join

Not sure if my Inner join is efficient SQL


SELECT concat(e.FirstName, e.LastName), o.OrderID, o.OrderDate, p.ProductName, c.CategoryName, od.Quantity, od.UnitPrice, od.Discount, ((od.UnitPrice* od.Quantity)*(1-od.Discount)) AS 'Total Item Price', Country, Region, City
FROM Employees e
INNER JOIN Orders o
    ON  e.EmployeeID = o.EmployeeID
INNER JOIN [Order Details] od
    ON o.OrderID = od.OrderID
INNER JOIN Products p
    ON od.ProductID = p.ProductID
INNER JOIN Categories c
    ON p.CategoryID = c.CategoryID
WHERE e.Country = 'USA' OR e.Country = 'France' OR e.Country = 'Germany' OR e.Country = 'Brazil'
ORDER BY OrderDate DESC, e.FirstName;

I'm thinking there is a much easier way to do this query? Any input on this guys?


Solution

  • It looks like the inner joins are doing what you need. The only thing I would change is the where, I would change it to

    WHERE e.Country IN ('USA', 'France', 'Germany', 'Brazil')
    

    Thank you