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

Était-ce utile?

La solution

You can do it with JOIN as

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

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top