slazter25
slazter25

Reputation: 13

Swapping two columns without updating

I'm working on a football league, and I need to insert the second leg matches, how can I swap the home team with the away team without an update?

I already have every game for leg 1 with the columns:

game_id Home Away

and the data:

1 Team A x Team B
2 Team C x Team D
3 Team E x Team F

I want to insert this on the table:

4 Team B x Team A
5 Team D x Team C
6 Team F x Team E

in order for it to stay:

1 Team A x Team B
2 Team C x Team D
3 Team E x Team F
4 Team B x Team A
5 Team D x Team C
6 Team F x Team E

Upvotes: 1

Views: 55

Answers (1)

Tree Frog
Tree Frog

Reputation: 666

If the Id is an auto generated identity field you should just be able to do

insert into league (teamA, teamB) select teamB, teamA from league

Upvotes: 3

Related Questions