Subquery returned more than 1 value

Posted on 2010-01-05
Last Modified: 2012-05-08
INSERT INTO information
(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)
Question by:rgb192
    LVL 8

    Accepted Solution

    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.

    LVL 60

    Expert Comment

    you can't run inserts in such a your records (columns) relate to each other?
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    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

    Author Closing Comment

    > =

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now