1

I have this query:

UPDATE Table1 SET Table1.parameterA = 1
  WHERE Table1.parameterB = ? 
  AND Table1.parameterC = (
    SELECT Table2.id 
    FROM Table2 
    WHERE Table2.parameterD = ? AND Table2.date > ?
  )

This is not working because the select is returning multiple rows:

{ Error: ER_SUBQUERY_NO_1_ROW: Subquery returns more than 1 row }

Is it possible a workaround to do this multiple update?

2
  • 1
    try changing AND Table1.parameterC = ( to AND Table1.parameterC IN ( Commented Jul 13, 2017 at 9:06
  • if you are using '=' your subquery must return just 1 row. Commented Jul 13, 2017 at 9:10

1 Answer 1

3

when using = SQL expects a single value.

if you want to work with a list of results - you should use IN like this:

UPDATE Table1 SET Table1.parameterA = 1
   WHERE Table1.parameterB = ? 
   AND Table1.parameterC IN (
     SELECT Table2.id 
       FROM Table2 
       WHERE Table2.parameterD = ? AND Table2.date > ?
   )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.