I have a correlated subquery in an update that used to work just fine (last year it worked; this year I made some small changes to the schema and the data are different). Now it fails with “Subquery returns more than 1 row” error.
The query is this:
update mytable as q
set p_ID = (
select ap.pID
from aptable as ap
where ap.ID = q.ID
and ap.txnDate is not NULL
order by ap.txnDate
limit 1 offset 2
)
Weird, eh?
To find where it returns more than one row – which should be impossible, I prepared the query with the addition of “where ap.ID = ?” and ran the query in a loop for each valid ID value. Guess what – it worked all the way through.
Any ideas of what’s going on here?
I’m guessing it’s due to Bug #20519: “‘Subquery returns more that 1 row’ error with ‘limit x, 1′”, which was fixed in MySQL 5.0.25.