PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Randomly Accessing A Record From Non-Keyed Database
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Randomly Accessing A Record From Non-Keyed Database

Réponse
 
LinkBack Outils de la discussion
Vieux 10/02/2008, 00h36   #1
Fred Atkinson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Randomly Accessing A Record From Non-Keyed Database

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
  Réponse avec citation
Vieux 10/02/2008, 00h45   #2
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Randomly Accessing A Record From Non-Keyed Database

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
  Réponse avec citation
Vieux 10/02/2008, 01h22   #3
Evan Keel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Randomly Accessing A Record From Non-Keyed Database


"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


  Réponse avec citation
Vieux 10/02/2008, 02h38   #4
Fred Atkinson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Randomly Accessing A Record From Non-Keyed Database

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
  Réponse avec citation
Vieux 10/02/2008, 03h02   #5
Fred Atkinson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Randomly Accessing A Record From Non-Keyed Database

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
  Réponse avec citation
Vieux 10/02/2008, 03h03   #6
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Randomly Accessing A Record From Non-Keyed Database

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
==================

  Réponse avec citation
Vieux 10/02/2008, 03h08   #7
Fred Atkinson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Randomly Accessing A Record From Non-Keyed Database

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
  Réponse avec citation
Vieux 10/02/2008, 03h12   #8
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Randomly Accessing A Record From Non-Keyed Database

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
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12910 seconds with 16 queries