Announcement

Collapse
No announcement yet.

Subquery returns more than 1 row ???

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Subquery returns more than 1 row ???

    Hello all,
    I'm trying to use this sql to sincronize details rows and master data:

    UPDATE `orders_details` INNER JOIN orders ON orders_details.Id_Ord = orders.Id_Ord
    SET orders_details.OrderID = ( SELECT orders.OrderID FROM orders WHERE orders_details.Id_Ord = orders.Id_Ord )

    I got this error....

    #1242 - Subquery returns more than 1 row

    What does it means ?

    Is it correct to add on sub query ....
    GROUP BY orders_details.Id_Ord

    In this way it do not give error but I don't know if it's correct
    Last edited by giovannino; 11-13-2015, 04:03 PM.

  • #2
    You are using an update which means that the subquery is only allowed to return one row as you are updating only one row. Appearantly your subquery returns more and thus the database doesn't know which record to use for update. Ordersdetails are probabely the list of items you have on your order, so in this case all will have the same Id_Ord. For mysql you could apply a limit 0,1 to limit the subselect to one record only.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      OK . Thanks !!

      Comment

      Working...
      X