Question

What I need is to loop inside Request table and set 1 only those numbers which exits in request table.

UPDATE Number SET requested=1 WHERE id=(SELECT numberID FROM Request)

Returns error Subquery returns more than 1 row

Was it helpful?

Solution

You can do it with JOIN as

UPDATE
Number
inner join Request on Request.numberID = Number.id
set Number.requested = 1 

OTHER TIPS

Use

UPDATE Number n, Request r SET n.requested = 1 WHERE n.id = r.numberID

Use this

UPDATE Number
SET requested=1 
WHERE id IN (SELECT numberID FROM Request)

Please remember, "=" only can connect one value to one value. In your example, left side of "=" is a value, but on the right side, it is a set of values returned by the subquery. This is not going to work in database.

Hope it helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top