0

is it possible to update multiple row with multiple where?

    id | formid
   PK 1  | 2
   PK 2  | 2

i need to switch id 1 to 2 and 2 to 1 also need to filter with where formid = 2. is it possible ?

Ibnu Habibie
  • 721
  • 1
  • 9
  • 20

2 Answers2

0

You can do that...by using this query

update mytbl a
inner join mytbl b on a.formid <> b.formid
set a.id = b.id
where a.id in (1,2) and b.id in (1,2)
Kunal
  • 604
  • 10
  • 18
0

Have you tried anything that does not work?

This is a problem of switching 2 values. You can try with temporary variable as said here.

Another option in by join, as stated here.

Community
  • 1
  • 1