Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Subquery returned more than 1 value

INSERT INTO information
SELECT
(SELECT productid from products where productid = 149880 ),
(select internalsku from products where productid IN (select productid from orderitems left join orders on orderitems.orderid = orders.orderid where orderitems.orderid > '7000149' )),
(SELECT orderid from orders where orderid = 7000149 )
select * from information


Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

(20 row(s) affected)
0
rgb192
Asked:
rgb192
1 Solution
 
Jon500Commented:
If you run just this Select:

select productid from orderitems left join orders on orderitems.orderid = orders.orderid where orderitems.orderid > '7000149'

Don't you find that it returns more than one row? If it does, your IN clause will cause the internalsku to return more than one value.

Regards,
Jon500
0
 
chapmandewCommented:
you can't run inserts in such a way....do your records (columns) relate to each other?
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
INSERT INTO information
SELECT  p.productid ,p.internalsku , i.orderid
from products p
inner join orderitems i on  p.productid = i.productid
inner join orders o on o.orderid = i.orderid
where i.orderid > '7000149' and p.productid = 149880
0
 
rgb192Author Commented:
> =
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now