xChaax
xChaax

Reputation: 323

How to update values in multiple rows mysql?

I have a table named jemaah :

   ID  name age gender
    1    a    2    p
    2    b    3    l
    3    c    1    l
    4    d    5    p

My question is how to update the value in gender column. For example i want to change the value p into f and l into m. All to together there are thousand rows.

Upvotes: 0

Views: 1324

Answers (3)

Dale Corns
Dale Corns

Reputation: 225

2 updates need to be done

UPDATE tablename SET gender = "f" WHERE gender = "p"

UPDATE tablename SET gender = "m" WHERE gender = "l"

Upvotes: 0

Dave Anderson
Dave Anderson

Reputation: 12294

UPDATE jemaah SET gender = CASE gender WHEN 'p' THEN 'f' WHEN 'l' THEN 'm' END

Upvotes: 1

Patrick Moore
Patrick Moore

Reputation: 13354

UPDATE jemaah SET gender = 'f' WHERE gender = 'p';
UPDATE jemaah SET gender = 'm' WHERE gender = 'l';

Upvotes: 4

Related Questions