Answer the question
In order to leave comments, you need to log in
How to compose correct update sql (with nested query) query in db?
I have a query like:
UPDATE
requests
SET
requests.title = "договор для АО",
requests.responsible = (SELECT requests.responsible, users.id FROM requests, users WHERE "переменная с текстом" = users.username),
requests.datecreate = "2018-09-18",
requests.percent = "0",
comment = "коммент",
status = (SELECT requests.status, status.id FROM requests, status WHERE "переменная с текстом" = status.status)
WHERE
requests.id = 4
Answer the question
In order to leave comments, you need to log in
You didn't specify how the requests and users tables, as well as the requests and status tables, are related.
Both subqueries in this case must return one row and one field for each requests entry, otherwise there will be an error.
If there is no connection, you can try this:
UPDATE requests
SET requests.title = "договор для АО",
requests.responsible = ISNULL((SELECT id
FROM users
WHERE username = "переменная с текстом"), requests.responsible),
requests.datecreate = "2018-09-18",
requests.percent = "0",
comment = "коммент",
status = ISNULL((SELECT id
FROM status
WHERE status = "переменная с текстом"), requests.status)
FROM requests
WHERE requests.id = 4
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question