Вопрос

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

Это было полезно?

Решение

You can do it with JOIN as

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

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top