Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this query return this message

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.


What I have tried:

SQL
SELECT (a.NumUnit*(SELECT  sp.PriceUnitSale
FROM    SalePrice sp
        INNER JOIN
        (
            SELECT  ProNo, MAX(PriceLastDate) max_date
            FROM    SalePrice
            GROUP   BY ProNo
        ) spt ON  sp.ProNo =a.ProNo AND sp.PriceLastDate = spt.max_date))Amount

FROM    StoreBalance a
        INNER JOIN
        (
            SELECT  ProNo, MAX(BalanceDate) max_date,MAX(BalanceNo) max_No
            FROM    StoreBalance
            GROUP   BY ProNo
        ) b ON  a.ProNo =b.ProNo AND
                a.BalanceDate = b.max_date and  a.BalanceNo = b.max_No and year(BalanceDate)='2019'
Posted
Updated 1-Oct-19 21:59pm
v2
Comments
Jörgen Andersson 2-Oct-19 5:54am    
I bet you're having duplicate rows with PriceLastDate = MAX(PriceLastDate)

The error means exactly what it says: your subquery returned more than one value.
Your code is effectively
SQL
SELECT a_column * (a_subquery) Amount FROM Mytable
And a_subquery return more than one value - which means you are asking SQL to multiply NumUnit by several values and it won't do that.

You need to look at your subquery closely - and I'd suggest running it on it's own to see what it does return - and sort it out so that it does return just one value.

Unfortunately, we can't do that: we don't have access to your DB, and we have no idea what you are trying to get NumUnit multiplied by!
 
Share this answer
 
Comments
Maciej Los 2-Oct-19 3:57am    
5ed!
OriginalGriff is right.
In addition i'd strongly recommend to read this interesting article: Finding the reason for the error “Subquery returned more than 1 value” | SQL Studies[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900