Performance tuning a group by with percentage
Running MySql 5.0.85, I need to be as efficient as possible about a few queries. If I could get a little review, I would appreciate it. I collect data in the millions, and need the top 50 grouped by one field, with a percentage of how much those top 50 occupy. Here is what I have come up with... 1) I have a feeling I can be more efficient, perhaps with a join 2) How can I get the percentage to be of precision in the hundredths, so * 100.00 ie: .07 becomes 7.00, getting SQL errors if I (percentage * 100) SELECT user_agent_parsed, user_agent_original, COUNT( user_agent_parsed ) AS thecount, COUNT( * ) / ( SELECT COUNT( * ) FROM agents ) AS percentage FROM agents GROUP BY user_agent_parsed ORDER BY thecount DESC LIMIT 50; Second issue, once a day I need to archive the result of the above. Any suggestions on how to best to do that? I can schedule with cron, or in my case, launchd, unless someone has a better suggestion. Would you think that a simple 'SELECT (the above) INTO foo' would suffice? ( I will add a date stamp as well ) Thanks all. -- Scott * If you contact me off list replace talklists@ with scott@ * -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Change clock/timezone time without restart mysql
Hi, I need to change the computer clock (changing the /etc/zoneinfo) but I would not restart de MySQL service. The NOW() still returning the old time... Thanks, Jonas
Re: Change clock/timezone time without restart mysql
Jonas, your information is somewhat incomplete, but still: Jonas Silveira wrote: > Hi, > > > > I need to change the computer clock (changing the /etc/zoneinfo) but I would From the file name, I assume it is some Unix platform. > not restart de MySQL service. The NOW() still returning the old time... "Works as designed": A process inherits time zone information when it starts, from the parent and the then valid environment. This also holds for the MySQL server. That is why time zone information contains the info about when daylight saving time starts / ends: A process starting before the change and still running after that will use the correct time only because it got the information (about the change point) already when it started. HTH, Jörg -- Joerg Bruehe, MySQL Build Team, joerg.bru...@sun.com (+49 30) 417 01 487 Sun Microsystems GmbH, Komturstraße 18a, D-12099 Berlin Geschaeftsfuehrer: Thomas Schroeder, Wolfgang Engels, Wolf Frenkel Vorsitzender des Aufsichtsrates: Martin Haering Muenchen: HRB161028 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
deleting the node, and child nodes/leafs for a db/tbl..
Hi. I've got a situation where I have a couple of tables. The relationship between the tables is one of parent/child. I'm trying to figure out the best approach to being able to delete the associated children in the child tbls, of a given parentID in the parentTBL... I've checked into various sites/articles on the 'net.. but i'm not sure how to accomplish this without getting into recursion... I'm using python/php as the interface language to the test tbls.. Any pointers/articles/test code (code/schema) would be helpful... Thanks -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
insert random number into table
Hello All, I am trying to insert a unique random number* with each row when inserting into a table. I can do it in the application layer (php) but just wondering if there is an easier way in the database layer. Thanks Ray * for example, when registering a person for a contest, I want to give them a unique, random identifier. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: Inserting an Image
Well, I've spent the last 2 days chasing my tail just to discover that there was some screwy python deal going on. The following code works: sql = "update productsX set Name='%s', Title='%s', Description='%s', Price='%s', Bedrooms='%s', Bathrooms='%s', Conditions='%s', Acreage='%s', Construction='%s', Location='%s', Estate='%s', Address='%s', Furnished='%s' where ID=%s;" % (name, title, description, price, bedrooms, bathrooms, conditions, acreage, construction, location, estate, address, furnished, id) cursor.execute(sql) cursor.execute('update productsX set pic1=%s, pic2=%s, pic3=%s, pic4=%s, pic5=%s, pic6=%s where ID=%s;', (pic1, pic2, pic3, pic4, pic5, pic6, id)) Notice I have to use two separate sql calls and the only differences between them are that the first have the strings in quotes AND there is a % sign between the string widgets and the variables that replace them. That's it! Wonder what the *#&^%( difference that makes. V On Thu, Oct 15, 2009 at 4:54 PM, Michael Dykman wrote: > Victor, > > again, your question has more to do with python usage than MySQL > per-se.. you would be better off pursuing these questions in a python > forum. > > - michael dykman > > On Thu, Oct 15, 2009 at 3:28 PM, Gavin Towey wrote: > > "Image in string form" sounds like you're not inserting binary data, > rather some sort of encoded data. Even if it is binary, you'll have to > escape at least end quote characters, you can see clearly at the top of your > data there is : > > 'ÿÃÿà JFIF ÿÃC "" $(4,$&1' > > > > > > Another thing to think about is storing image data directly in a database > is often not a good idea. See these links for more info: > > > > > http://mysqldump.azundris.com/archives/36-Serving-Images-From-A-Database.htmland > http://hashmysql.org/index.php?title=Storing_files_in_the_database > > > > Regards, > > Gavin Towey > > > > -Original Message- > > From: Victor Subervi [mailto:victorsube...@gmail.com] > > Sent: Thursday, October 15, 2009 12:05 PM > > To: mysql@lists.mysql.com > > Subject: Inserting an Image > > > > Hi; > > I have successfully inserted images, like yesterday, before into MySQL > with > > the following code: > > > > sql = 'update productsX set pic1="%s" where ID=2;' % pic1 > > cursor.execute(sql) > > where pic1 is simply an image uploaded through a form then sent over > without > > any alteration to another (python) script that uploads it. Printing it > out > > looks like this (other variables included): > > > > update productsX set Name=%s, Title=%s, Description=%s, Price=%s, > > Bedrooms=%s, Bathrooms=%s, Conditions=%s, Acreage=%s, Construction=%s, > > Location=%s, Estate=%s, Address=%s, Furnished=%s, pic1=%s, pic2=%s, > pic3=%s, > > pic4=%s, pic5=%s, pic6=%s where ID=%s;', ('name1', 'title1', 'descr1', > > '1.1', '2', '1', 'New', '1.5', 'New', 'arbor', 'abor', 'abor', > 'Furnished', > > 'ÿÃÿà JFIF ÿÃC "" $(4,$&1' -=-157:::#+?D?8C49:7ÿÃC 7% > > %77ÿà y| " ÿà ÿÃM !1A Qa > "qs > > ³ 27Bbcâ #46Rrt⡱² $'3Câ%5DTUÆâ¢£Ãñÿà ÿà ÿà ?Å*â¹RP⥨% dâpªÃcµkä«âøZ Ãá > îj > > Xêxö, `...@$ý <%6...@$ý> ô¨2mÃžà ¦ ÃRÃ¥¬ò guD|!%bO :ðçâ Zâ¦Ã¦ÂµÃÃvsM¡·¢&T âŬ > ºâ > > âñ â1ö¶KT[%¦-² {â£6 Ã÷ââNI=äÃfà ø/RhÃîRâ³q1 QüÃâÆÅ¸ ÆE Å Å ( (¢ŠŠ( (¢ŠŠ( > Ãê > > ´{ âmÃYü VTââ pUŽI $à Qvà üÃ/ZÃì{IrÃ,´£à x à #¸$Š·÷F_à ë}â¦â¦Ã¡RTdH ó > > Ã#ÃUâö*DÃõ¨Yt]ž îêà +p}5ùêÿ¹F â vã Ãöy5Ãâ\ËëO Žc 'ö(Ãõku-´^4õÃà ã8Ãð%$ > ì84 > > Ã*ø G¥·T Vû#µc æ ·uÃ; Ã"ÃusN\\Ãâ¹5{ÃøvoòÃû@ é ¼ÃCP U > > ¤¡%KPJR2I8T+´½¨®{Ã{:)kzDâ¡; &2~1' ¤â ïÃÃA¶Ãº®Ãª5 Ãú AiMçá âO â8 â¢tÃpHâNà > > Uºl¤Ãmë¸é«Ãà øéà ûâ7�...@guc q à Šhö cFà Ã\çðäÃâ¡Ã^8$} ä Ã=i² Aj ©ôŠ«â°J_u > > /Â¥<Æâ°%*áÃËÃ;˦ TÃö©6)WûjÃZ`ü dÃsæâÃHQB E@ m5à QE EbÃî > > ÃP]âºqâÃxçyn8pÿÃâ¡3IP5⨿´©úgL2å©K)aéÃû ¼ 5 ãâs 8žT æÃæ*ýµ)QâÂä4óp⺠¦0 > ?ÃU]B > > r + ç\»]_"éŸ pTÅŸXU] Ãò  â¬gK ®tTxò^iâ° Ã 4â¡ Rè ¤ à 8 Y«âº` üM ]Êóżâ¬ÃK > > ,Â¥Iü29 ÃÆÅ¾6â¢iUâ¡]ã Ã/²G 5~xã8öTñá§Sà âºÂ«Â¿Ã©ËÃà ¥ Ã[ ;ôâ¡Qß~4»vÃOìðu âëÃà > à > > %®a d⟠g ¨Ãe1. õõÅà æû2 ëÃG$4>9' )$xç h3öâ°Â´Ã® ôHî.%Å,â ã à º x Sà â¡Å½3Nû > > ÃÃAûêº5ÅâË Â¨qÃà § Ë ÃÃh±ìÃOÃÃV¢Ⱐ>`ÃTÃÂà à «.¤¨¥Gžè<â¬Ã£Å½g½ãP<ìM£h¸1 [ > Ãî;J)mA- > > ÃR8 :g⢠ãXjû> ââ¢Wâ¡Ã ââ Xho8é ÷Gâ¡yÃâ8ñ â¡Â¤Ãµ5ëQÂ¥â°Å¸{žCjxo7"LÃàà ÃG#Ú⡠➨ t > > ââº-LjFžhÃËÃXyÂ¥(⦠\8) ŽJð} -ÃKp¬â TâPÃu Åî â¬âÅ â ôTc¢öâ¦Â§ÃZ ëõùµMì > hâµ<öwŽ7â¬Ã > > 1ÃâÅ¡Ã2Â7 ó ";= & b*Sê e Ã7xž|p è:@Ã[YÃÃq.1 Ãs¸'â¬b2 BOÃ_!è > ¡ > >
RE: insert random number into table
There is a RAND function in MySQL, but if you need to guarantee that the identifiers are unique you should consider using an auto-increment field. If that isn't unique enough, you can use the UUID or UUID_SHORT functions. Theoretically, those should return values that are unique across the Internet (at least). Regards, Jerry Schwartz The Infoshop by Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com >-Original Message- >From: Ray [mailto:r...@stilltech.net] >Sent: Friday, October 16, 2009 11:43 AM >To: mysql@lists.mysql.com >Subject: insert random number into table > >Hello All, >I am trying to insert a unique random number* with each row when inserting >into a table. I can do it in the application layer (php) but just wondering >if >there is an easier way in the database layer. >Thanks >Ray > >* for example, when registering a person for a contest, I want to give them a >unique, random identifier. > >-- >MySQL General Mailing List >For list archives: http://lists.mysql.com/mysql >To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- >infoshop.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: insert random number into table
On October 16, 2009 10:57:48 am Jerry Schwartz wrote: > There is a RAND function in MySQL, but if you need to guarantee that the > identifiers are unique you should consider using an auto-increment field. > > If that isn't unique enough, you can use the UUID or UUID_SHORT functions. > Theoretically, those should return values that are unique across the > Internet (at least). > > Regards, > > Jerry Schwartz > The Infoshop by Global Information Incorporated > 195 Farmington Ave. > Farmington, CT 06032 > > 860.674.8796 / FAX: 860.674.8341 > > www.the-infoshop.com > > >-Original Message- > >From: Ray [mailto:r...@stilltech.net] > >Sent: Friday, October 16, 2009 11:43 AM > >To: mysql@lists.mysql.com > >Subject: insert random number into table > > > >Hello All, > >I am trying to insert a unique random number* with each row when inserting > >into a table. I can do it in the application layer (php) but just > > wondering if > >there is an easier way in the database layer. > >Thanks > >Ray > > > >* for example, when registering a person for a contest, I want to give > > them a unique, random identifier. > > > >-- > >MySQL General Mailing List > >For list archives: http://lists.mysql.com/mysql > >To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- > >infoshop.com Thanks for the replies. I think I'll use the php solution as it is the better match for what I am trying to do. I'l keep the UUID functions in mind for future use though. Ray -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: insert random number into table
Don't try to give them a random number, instead use a table with a primary key that is AUTO_INCREMENT. Then you just insert the record, and afterwards SELECT LAST_INSERT_ID(); to retrieve the id for the record created. With random numbers, you're going to have more collisions when you add more records. Regards, Gavin Towey -Original Message- From: Ray [mailto:r...@stilltech.net] Sent: Friday, October 16, 2009 8:43 AM To: mysql@lists.mysql.com Subject: insert random number into table Hello All, I am trying to insert a unique random number* with each row when inserting into a table. I can do it in the application layer (php) but just wondering if there is an easier way in the database layer. Thanks Ray * for example, when registering a person for a contest, I want to give them a unique, random identifier. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=gto...@ffn.com The information contained in this transmission may contain privileged and confidential information. It is intended only for the use of the person(s) named above. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: insert random number into table
>-Original Message- >From: Ray [mailto:r...@stilltech.net] >Sent: Friday, October 16, 2009 1:10 PM >To: mysql@lists.mysql.com >Subject: Re: insert random number into table > >On October 16, 2009 10:57:48 am Jerry Schwartz wrote: >> There is a RAND function in MySQL, but if you need to guarantee that the >> identifiers are unique you should consider using an auto-increment field. >> >> If that isn't unique enough, you can use the UUID or UUID_SHORT functions. >> Theoretically, those should return values that are unique across the >> Internet (at least). >> >> Regards, >> >> Jerry Schwartz >> The Infoshop by Global Information Incorporated >> 195 Farmington Ave. >> Farmington, CT 06032 >> >> 860.674.8796 / FAX: 860.674.8341 >> >> www.the-infoshop.com >> >> >-Original Message- >> >From: Ray [mailto:r...@stilltech.net] >> >Sent: Friday, October 16, 2009 11:43 AM >> >To: mysql@lists.mysql.com >> >Subject: insert random number into table >> > >> >Hello All, >> >I am trying to insert a unique random number* with each row when inserting >> >into a table. I can do it in the application layer (php) but just >> > wondering if >> >there is an easier way in the database layer. >> >Thanks >> >Ray >> > >> >* for example, when registering a person for a contest, I want to give >> > them a unique, random identifier. >> > >> >-- >> >MySQL General Mailing List >> >For list archives: http://lists.mysql.com/mysql >> >To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- >> >infoshop.com > > >Thanks for the replies. I think I'll use the php solution as it is the better >match for what I am trying to do. I'l keep the UUID functions in mind for >future use though. >Ray > [JS] Just remember that the pseudo-random numbers that come out of a computer, regardless of where or how they are generated, are not guaranteed to be unique. Although the odds of a collision are slim, my philosophy has always been "if it's possible, it will happen - in the middle of your vacation". If you want to generate UUIDs in PHP, take a look at http://www.shapeshifter.se/2008/09/29/uuid-generator-for-php/ >-- >MySQL General Mailing List >For list archives: http://lists.mysql.com/mysql >To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- >infoshop.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: insert random number into table
In addition to what Gavin said. You seem to want some form of key perhaps to be able to identify the authenticity of your contest winner. An auto increment ID won't be very secure for that, but you still need it. Take a known combination of perhaps the key, name, email address, etc, and run a hashing function on it. Md5 will often suffice. This will give you a unique hash that only you know how it was made. You can inject some 'salt' into a known location to add more difficulty in guessing your hashing input. This hash will be asking too much of the user to hand type in, so I'm assuming you will accept it via a link in a URL. Or ask for whatever you used to make the hash and rehash that and compare your internal stored result. If not, for your needs you may be able to safely remove ambiguous characters, and take a substring of it to make it shorter. It's also quite easy to create a dictionary of words and create a function that can make word1-xx-word2 and end up with red-56-car. -- Scott Iphone says hello. On Oct 16, 2009, at 11:25 AM, Gavin Towey wrote: Don't try to give them a random number, instead use a table with a primary key that is AUTO_INCREMENT. Then you just insert the record, and afterwards SELECT LAST_INSERT_ID(); to retrieve the id for the record created. With random numbers, you're going to have more collisions when you add more records. Regards, Gavin Towey -Original Message- From: Ray [mailto:r...@stilltech.net] Sent: Friday, October 16, 2009 8:43 AM To: mysql@lists.mysql.com Subject: insert random number into table Hello All, I am trying to insert a unique random number* with each row when inserting into a table. I can do it in the application layer (php) but just wondering if there is an easier way in the database layer. Thanks Ray * for example, when registering a person for a contest, I want to give them a unique, random identifier.
Re: insert random number into table
I always maintain a timestamp in my random numbers. As long as my precision is higher than my requests per second, wouldn't I be safe from collisions? Assuming a time machine is not invented. -- Scott Iphone says hello. On Oct 16, 2009, at 11:29 AM, "Jerry Schwartz" > wrote: JS] Just remember that the pseudo-random numbers that come out of a computer, regardless of where or how they are generated, are not guaranteed to be unique. Although the odds of a collision are slim, my philosophy has always been "if it's possible, it will happen - in the middle of your vacation". -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
inserting csv - solved, but more to the puzzle
In case anyone might find this of the least interest, probably not, but I always hope to add to discussion just as part of the thank you for help. Further work with same issues found that a file received from a PC based client, if opened in PC environment, didn't have the same problems (so far) as if opened in a Mac environment. The next file I had to work with in this particular project, I opened in PC, then uploaded using phpMyadmin with no issues. Same client, same type of file. So, maybe there is a PC/Mac thing happening to cause the line 17, missing commas in csv? Just a thought. If anyone has any insight, most appreciated. -- Patrice Olivier-Wilson 888-385-7217 http://biz-comm.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: inserting csv - solved, but more to the puzzle
I've run into similar situations w/regard to Mac vs PC CSV files, it usually has to do with the EOL character sequence. Macs use LF (chr(10)), while PCs use CRLF (chr(13)chr(10)). andy Patrice Olivier-Wilson wrote: In case anyone might find this of the least interest, probably not, but I always hope to add to discussion just as part of the thank you for help. Further work with same issues found that a file received from a PC based client, if opened in PC environment, didn't have the same problems (so far) as if opened in a Mac environment. The next file I had to work with in this particular project, I opened in PC, then uploaded using phpMyadmin with no issues. Same client, same type of file. So, maybe there is a PC/Mac thing happening to cause the line 17, missing commas in csv? Just a thought. If anyone has any insight, most appreciated. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: inserting csv - solved, but more to the puzzle
Thank you for the confirmation, Andy. I appreciate your patience with such a newbie who is just trying to learn. Andy Wallace wrote: I've run into similar situations w/regard to Mac vs PC CSV files, it usually has to do with the EOL character sequence. Macs use LF (chr(10)), while PCs use CRLF (chr(13)chr(10)). andy Patrice Olivier-Wilson wrote: In case anyone might find this of the least interest, probably not, but I always hope to add to discussion just as part of the thank you for help. Further work with same issues found that a file received from a PC based client, if opened in PC environment, didn't have the same problems (so far) as if opened in a Mac environment. The next file I had to work with in this particular project, I opened in PC, then uploaded using phpMyadmin with no issues. Same client, same type of file. So, maybe there is a PC/Mac thing happening to cause the line 17, missing commas in csv? Just a thought. If anyone has any insight, most appreciated. -- Patrice Olivier-Wilson 888-385-7217 http://biz-comm.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: insert random number into table
On October 16, 2009 12:29:42 pm Jerry Schwartz wrote: > >-Original Message- > >From: Ray [mailto:r...@stilltech.net] > >Sent: Friday, October 16, 2009 1:10 PM > >To: mysql@lists.mysql.com > >Subject: Re: insert random number into table > > > >On October 16, 2009 10:57:48 am Jerry Schwartz wrote: > >> There is a RAND function in MySQL, but if you need to guarantee that the > >> identifiers are unique you should consider using an auto-increment > >> field. > >> > >> If that isn't unique enough, you can use the UUID or UUID_SHORT > >> functions. Theoretically, those should return values that are unique > >> across the Internet (at least). > >> > >> Regards, > >> > >> Jerry Schwartz > >> The Infoshop by Global Information Incorporated > >> 195 Farmington Ave. > >> Farmington, CT 06032 > >> > >> 860.674.8796 / FAX: 860.674.8341 > >> > >> www.the-infoshop.com > >> > >> >-Original Message- > >> >From: Ray [mailto:r...@stilltech.net] > >> >Sent: Friday, October 16, 2009 11:43 AM > >> >To: mysql@lists.mysql.com > >> >Subject: insert random number into table > >> > > >> >Hello All, > >> >I am trying to insert a unique random number* with each row when > >> > inserting into a table. I can do it in the application layer (php) but > >> > just wondering if > >> >there is an easier way in the database layer. > >> >Thanks > >> >Ray > >> > > >> >* for example, when registering a person for a contest, I want to give > >> > them a unique, random identifier. > >> > > >> >-- > >> >MySQL General Mailing List > >> >For list archives: http://lists.mysql.com/mysql > >> >To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- > >> >infoshop.com > > > >Thanks for the replies. I think I'll use the php solution as it is the > > better match for what I am trying to do. I'l keep the UUID functions in > > mind for future use though. > >Ray > > [JS] Just remember that the pseudo-random numbers that come out of a > computer, regardless of where or how they are generated, are not guaranteed > to be unique. Although the odds of a collision are slim, my philosophy has > always been "if it's possible, it will happen - in the middle of your > vacation". > > If you want to generate UUIDs in PHP, take a look at > http://www.shapeshifter.se/2008/09/29/uuid-generator-for-php/ > > >-- > >MySQL General Mailing List > >For list archives: http://lists.mysql.com/mysql > >To unsubscribe:http://lists.mysql.com/mysql?unsub=jschwa...@the- > >infoshop.com Thanks for all the suggestions and points. There are definitely some I will keep in mind for future projects. auto increment won't work because I don't want the number to be based on the order of assignment. I probably should have been more clear. What I am trying to do is randomly assign one of a fixed pool of numbers uniquely to each row. What I ended up doing is (in PHP): SELECT all used numbers and put them in an array. create an array of all allowed numbers. combine the two arrays such that all available numbers are left in a third array with index numbers from 1 counting up sequentially. I then randomly choose one of those numbers and write it to the table. Thanks again for all your suggestions. Ray -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org