[prog] mysql insert/update/replace

Wolf Rising wolfrising at gmail.com
Mon Jul 25 14:12:22 EST 2005


Hello :-)

I can get one row to update but I can't get all four to update at once but yes
something similar to

update status set foo = "$bar", fee = "$fum" where date = "$date"

but since my insert statement affects all four rows at once I was
trying to figure out
how to update all four rows at once.
I thought something like:

update status set ('1', now(), '$one'), ('2', now(),
'$two'), ('3', now(),'$three'), ('4', now(),'$four') where date = now();

but obviously that didn't work :-) I suppose I could always delete
everything and
then run the insert statement again?

Thank you :-)

On 7/24/05, Michelle Murrain <michelle at murrain.net> wrote:
> 
> 
> On Jul 24, 2005, at 9:12 PM, Wolf Rising wrote:
> 
> Hi,
> 
> I'm trying to have a form automatically update(overwrite) a previous
> entry if needed, I have a select statement to check if any entries
> already exists:
> 
> select * from status where date = now();
> 
> if this returns nothing I do an insert:
> 
> $query = "insert into status values ('1', now(), '$one'), ('2', now(),
> '$two'), ('3', now(),'$three'), ('4', now(),'$four');";
> 
> there are four rows each time that need to be effected. If the
> entries already exist I want to be able to update/replace the
> current entries with new ones. I had found on duplicate key but
> it doesn't work with the older version of mysql that is installed.
> 
> Is it possible using either update or replace to effect all
> four rows the way it's possible to insert the information for
> all four rows at once?
> 
> 
> Well, you need some sort of update query, that selects the four rows, like:
> 
> update status set foo = "$bar", fee = "$fum" where date = "$date"
> 
> Is that the sort of thing you are looking for?
> 
> It's hard to write something more specific - because I'm not sure what your
> original query is supposed to do - it seems weird to create 4 records at
> once, but that could just be your specific application. (I'd try to make it
> one record, and increase the number of fields in the table, or make related
> tables, but I don't know enough about what you're trying to do.)
> 
> Michelle
>  
> Michelle Murrain
> Seminarian, Pacific School of Religion
> michelle at murrain.net
> AIM:pearlbear0
> Blog:www.pearlbear.us
> 
> 
> 
> 
> 
> 
> "Love the earth and the sun and the animals, despise riches, give alms to
> everyone that asks, stand up for the stupid and crazy, devote your income
> and labor to others, hate tyrants, argue not concerning God."  --Walt
> Whitman
> 
> 
> 
> 
> 
> 
>  
>


More information about the Programming mailing list