0

I want to update rows of scenario_id=1 from scenario_id=7 where name matches. The difference between scenario_id is not constant.

id|scenario_id|status|name
1 |1          |Passed|testcase_1
2 |1          |Passed|testcase_2
3 |1          |Failed|willPassInNextRun
4 |7          |Passed|testcase_1
5 |7          |Passed|willPassInNextRun

after the update table should look like below

id|scenario_id|status|name
1 |1          |Passed|testcase_1
2 |1          |Passed|testcase_2
3 |1          |Passed|willPassInNextRun
4 |7          |Passed|testcase_1
5 |7          |Passed|willPassInNextRun
3
  • What is the result you want ? Because I am not sure to understand. Commented Jul 4, 2013 at 15:39
  • Can you write a SELECT query that returns the correct result? Commented Jul 4, 2013 at 15:40
  • What should be updated? How should the table look afterwards? Commented Jul 4, 2013 at 17:02

2 Answers 2

1

To make it work also in SQLite, use standard SQL and look up the new value with a correlated subquery:

UPDATE MyTable
SET status = COALESCE((SELECT status
                       FROM MyTable AS T2
                       WHERE scenario_id = 7
                         AND T2.name = MyTable.name),
                      status)
WHERE scenario_id = 1
Sign up to request clarification or add additional context in comments.

Comments

0

Try this,

update table t1, table t2
 set t1.status=t2.status
 where t2.scenario_id=7 and t1.scenario_id=1
 and t1.name=t2.name
 and t1.status!=t2.status;

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.