tags:

views:

19

answers:

2

Great site, tons of help to me so far.

I have a database with 10,000+ rows.

There is a column ( tinyint(4) ) called ahtml.

I need to change ~500 of the rows for that column from 0 to 1.

I know there is a query I can run in phpadmin to do that instead of editing each row.

I need to change ALL of the 0's to 1's in the ahtml column.

Guidance please?

Thanks in advance...

+1  A: 

You can use a WHERE clause to select which rwows you want to update. You can test your query before you run the UPDATE by doing a SELECT:

select *
MyTable 
where ahtml = 0

When you are satisfied that you are selecting the right rows, do this:

update MyTable 
set ahtml = 1
where ahtml = 0
RedFilter
A: 

The following will set the ahtml field of all rows to 1, where it was 0:

UPDATE your_table SET ahtml = 1 WHERE ahtml = 0;

Simply replace your_table with the real name of your table.

Note that if your ahtml is a boolean field with just 1 and 0 values, this will practically set all your ahtml values to 1. In that case, you could also do:

UPDATE your_table SET ahtml = 1;

If you want to change all the 0s to 1s and all the 1s to 0s, then you may want to first set the 0s to 2s, then set the 1s to 0s, then set the 2s to 1s:

UPDATE your_table SET ahtml = 2 WHERE ahtml = 0;
UPDATE your_table SET ahtml = 0 WHERE ahtml = 1;
UPDATE your_table SET ahtml = 1 WHERE ahtml = 2;
Daniel Vassallo
Awesome thanks worked great!
Jim