2

SQL - Subquery returned more than one value. How to fix?

 3 years ago
source link: https://www.codesd.com/item/sql-subquery-returned-more-than-one-value-how-to-fix.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SQL - Subquery returned more than one value. How to fix?

advertisements

-- Using orders, customers, employees, and order details tables, select the Order Id, the Order Date, -- the customer company name, the employee last name, and the total amount paid (including freight, but ignoring discount) for each order

I feel like I'm very close with my answer, but I keep running into this one error. I'm new to databases so I assume I'm overlooking something simple. I've looked at other pages with the same error and nothing really made sense to me.

The subquery works by itself but when I throw it into the rest of the query I get this error: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Here is my query thus far:

Select (Select (Sum(UnitPrice * Quantity) + Freight) as AmountPaid
    From [Order Details], Orders
    Group By [Order Details].OrderID, Freight),
    OrderDate, [Order Details].OrderID, CompanyName, LastName
From [Order Details], Customers, Employees
Inner Join Orders ON OrderID=Orders.OrderID


Change

(Sum(UnitPrice * Quantity) + Freight)

Sum((UnitPrice * Quantity) + Freight)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK