Forum Moderators: open

Message Too Old, No Replies

Beginner at SQL, quick question

Modifying column values

         

fushi

9:01 pm on Dec 26, 2006 (gmt 0)

10+ Year Member



Hi, I'm new at MySQL, and I'm wondering, is there a way to change all of the values of a column to be a certain value while retaining the other column values?

Example:

Original table:

co1 co2 co3 co4
¦---¦---¦---¦---¦
¦ A ¦ A ¦ A ¦ A ¦
¦---¦---¦---¦---¦
¦ B ¦ B ¦ B ¦ B ¦
¦---¦---¦---¦---¦
¦ C ¦ C ¦ C ¦ C ¦
¦---¦---¦---¦---¦
¦ D ¦ D ¦ D ¦ D ¦
¦---¦---¦---¦---¦

perform the function on co2, and get:

co1 co2 co3 co4
¦---¦---¦---¦---¦
¦ A ¦ M ¦ A ¦ A ¦
¦---¦---¦---¦---¦
¦ B ¦ M ¦ B ¦ B ¦
¦---¦---¦---¦---¦
¦ C ¦ M ¦ C ¦ C ¦
¦---¦---¦---¦---¦
¦ D ¦ M ¦ D ¦ D ¦
¦---¦---¦---¦---¦

is there a way to do this (mySQL)?

Thanks!

cmarshall

9:27 pm on Dec 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure.

UPDATE your_table_name SET `c02`='M'

That will do it for every one. Specify a WHERE clause if you want to pick and choose. It can get a LOT more complex. SQL is an entire language unto itself, but this will give you what you want.

fushi

9:38 pm on Dec 26, 2006 (gmt 0)

10+ Year Member



Thanks! :)