|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Steve,
If you had a database that did not have a keyed field, what would be the best way to request a random record? I've already figured a way to generate a random number from one to the number of records in the database. But I'm not sure that's going to here. Any ideas? Regards, Fred |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Sun, 10 Feb 2008 01:36:05 +0100, Fred Atkinson <fatkinson@mishmash.com>
wrote: > Steve, > > If you had a database that did not have a keyed field, what > would be the best way to request a random record? SELECT .... ORDER BY RAND() LIMIT 1 -- Rik Wasmus |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"Fred Atkinson" <fatkinson@mishmash.com> wrote in message news:1khsq3p3grqhtgepom2g43gvunkbimpedd@4ax.com... > Steve, > > If you had a database that did not have a keyed field, what > would be the best way to request a random record? > > I've already figured a way to generate a random number from > one to the number of records in the database. But I'm not sure that's > going to here. > > Any ideas? > > Regards, > > > > Fred What is a non-keyed database? Do you mean no primary key or no indexes? Evan |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Sat, 9 Feb 2008 20:22:18 -0500, "Evan Keel"
<evankeel@sbcglobal.net> wrote: > >"Fred Atkinson" <fatkinson@mishmash.com> wrote in message >news:1khsq3p3grqhtgepom2g43gvunkbimpedd@4ax.com.. . >> Steve, >> >> If you had a database that did not have a keyed field, what >> would be the best way to request a random record? >> >> I've already figured a way to generate a random number from >> one to the number of records in the database. But I'm not sure that's >> going to here. >> >> Any ideas? >> >> Regards, >> >> >> >> Fred > >What is a non-keyed database? Do you mean no primary key or no indexes? > >Evan > Neither. I just want to randomly grab a record out of the database. Regards, Fred |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Sun, 10 Feb 2008 01:45:56 +0100, "Rik Wasmus"
<luiheidsgoeroe@hotmail.com> wrote: >SELECT .... ORDER BY RAND() LIMIT 1 Thank you, That worked BEAUTIFULLY. Regards, Fred |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Fred Atkinson wrote:
> On Sat, 9 Feb 2008 20:22:18 -0500, "Evan Keel" > <evankeel@sbcglobal.net> wrote: > >> "Fred Atkinson" <fatkinson@mishmash.com> wrote in message >> news:1khsq3p3grqhtgepom2g43gvunkbimpedd@4ax.com... >>> Steve, >>> >>> If you had a database that did not have a keyed field, what >>> would be the best way to request a random record? >>> >>> I've already figured a way to generate a random number from >>> one to the number of records in the database. But I'm not sure that's >>> going to here. >>> >>> Any ideas? >>> >>> Regards, >>> >>> >>> >>> Fred >> What is a non-keyed database? Do you mean no primary key or no indexes? >> >> Evan >> > Neither. > > I just want to randomly grab a record out of the database. > > Regards, > > > > Fred > Fred, It should be very rare you don't have a primary key on a table (except, perhaps, for a many-to-many link table, but even that typically has a primary key). You almost always need a way to uniquely identify a row in a table should you need to update or delete it. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Sat, 09 Feb 2008 22:03:59 -0500, Jerry Stuckle
<jstucklex@attglobal.net> wrote: >Fred, > >It should be very rare you don't have a primary key on a table (except, >perhaps, for a many-to-many link table, but even that typically has a >primary key). > >You almost always need a way to uniquely identify a row in a table >should you need to update or delete it. I do have a way to identify the row. It is a callsign. It's almost unique except that callsigns like W5YI have two different URLs in them (www.w5yi.com and www.w5yi.net). In that case, there are two entries for the call. Thanks for your feedback, Jerry, as always. Regards, Fred |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Fred Atkinson wrote:
> On Sat, 09 Feb 2008 22:03:59 -0500, Jerry Stuckle > <jstucklex@attglobal.net> wrote: > >> Fred, >> >> It should be very rare you don't have a primary key on a table (except, >> perhaps, for a many-to-many link table, but even that typically has a >> primary key). >> >> You almost always need a way to uniquely identify a row in a table >> should you need to update or delete it. > > I do have a way to identify the row. It is a callsign. It's > almost unique except that callsigns like W5YI have two different URLs > in them (www.w5yi.com and www.w5yi.net). In that case, there are two > entries for the call. > > Thanks for your feedback, Jerry, as always. > > Regards, > > > > > Fred > Fred, Almost is not the same thing. For instance, what happens if you change the w4yi.net to w4yi.com in the table? How can you differentiate between the two? I don't know what else is in the rest of your tables, but if that's a link table (the only two things are the call sign and the url), chances are the combination of the two should be the primary key (will keep you from having duplicates). -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
![]() |
| Outils de la discussion | |
|
|