The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

MYSQL Update Random Row? Possible? by MikeCDN 2005-05-04 12:53:17
Quick question, is it possible to update a random row in a MYSQL table? I need to randomly insert data.

Or do I need to select it randomly first, get the row id then update it?

I was trying

UPDATE 'info_grid' SET setting='$data' WHERE id=rand() AND setting='0'

didn't work so I tried

UPDATE 'info_grid' SET setting='$data' WHERE id=rand()

and then

UPDATE kingdoms_grid SET kingdom='1' WHERE rand();

No good.

Not possible? or am I missing something obvious? My SQL is a bit weak.
[ Reply ]
  I'm thinking you need to select first, by merlin2005-05-04 12:54:27
    cursor operations? by MikeCDN2005-05-04 12:56:42
  oops bad copy paste in there :) by MikeCDN2005-05-04 12:55:56
  SELECT, then UPDATE by placidpsychosis2005-05-04 13:25:44
    Thanks by MikeCDN2005-05-04 13:44:48
    Only if there's no deleted rows! (n/t) by Arachnid2005-05-04 13:47:17
  You can't just... by sylvan2005-05-04 13:31:38
    Erg.. by sylvan2005-05-04 13:40:47
  Reliable but slow: by Arachnid2005-05-04 13:49:07
  Here's what I would do in T-SQL. by YakkoWarner2005-05-04 14:05:13
    Best case: O(1). Worst case: infinity! (n/t) by Arachnid2005-05-04 14:17:40

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)