0

How do I update every column in a row if a certain condition in the column is met? Say if the status column of that row is 'underReview', then update the whole row with the request body. If the status column has other values, then do not execute the SQL query? I am using v8 btw.

I have tried the query below but it shows error.

IF ((SELECT status FROM tableName) = "underReview" WHERE id = ?) 
THEN
    UPDATE tableName
    SET columnA = ?, columnB = ?, columnC = ?, columnD = ?
    WHERE id = ?;
END IF
1
  • 1
    tnkh, welcome to the exquisite world of relational algebra, where procedural algorithms do not quite apply. Please, make no step further until you really understand what's implied on @Nick's answer. Commented Sep 27, 2019 at 4:16

1 Answer 1

3

Just add the condition on status to the WHERE clause in the UPDATE:

UPDATE tableName
SET columnA = ?, columnB = ?, columnC = ?, columnD = ?
WHERE id = ? AND status = 'underReview';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.