Hi,
When I do a select with a limit I get always the same records. Usually this
is the desidered effect.
But now I want to do a random select. So every time I do a select I should
get a different set of results.
What is the best way to achieve this effect?
Thanks,
Wim 3 2380
Wim Roffil wrote: Hi,
When I do a select with a limit I get always the same records. Usually this is the desidered effect.
But now I want to do a random select. So every time I do a select I should get a different set of results.
What is the best way to achieve this effect?
Thanks, Wim
What is your problem? Do you really want random records, or are you
bothered that you get the same records everytime you perform a select?
If its the latter, you should use a WHERE clause in your SELECT and
perhaps also a LIMIT start,rows
Thus,something like
SELECT firstname,lastname FROM myTable WHERE ID>10 LIMIT 5,12
will find all records that have ID>10 and return 12 records, starting
from the 5th one found (thus something like records with ID 15 to 27).
If you want to read random records, request a random record (I'm
assuming you've got a column/cell that is AUTO_INCREMENT that you could
use as reference).
Does that help you any?
randelld
"Randell D." <re******************************@fiprojects.moc > schreef in
bericht news:LpHQd.407506$8l.401215@pd7tw1no... Wim Roffil wrote: Hi,
When I do a select with a limit I get always the same records. Usually
this is the desidered effect.
But now I want to do a random select. So every time I do a select I
should get a different set of results.
What is the best way to achieve this effect?
Thanks, Wim
What is your problem? Do you really want random records, or are you bothered that you get the same records everytime you perform a select?
Thank you for your reply.
I need reaaly random records. From a big collection I want to show the
visitors of my webpage just 5 or 10. Because adjacent records may be related
they should be spread over the whole collection. AUTO_INCREMENT is not an
option: it is not already there and the query is not over the whole table
but over a part of it (there is a WHERE clause). If its the latter, you should use a WHERE clause in your SELECT and perhaps also a LIMIT start,rows
Thus,something like
SELECT firstname,lastname FROM myTable WHERE ID>10 LIMIT 5,12
will find all records that have ID>10 and return 12 records, starting from the 5th one found (thus something like records with ID 15 to 27).
If you want to read random records, request a random record (I'm assuming you've got a column/cell that is AUTO_INCREMENT that you could use as reference).
Does that help you any? randelld
try
select * from table order by rand() limit 0,5
This doesn't have the best performance for large recordset, but is ok
for small tables
--
Jay
Wim Roffil wrote: "Randell D." <re******************************@fiprojects.moc >
schreef in bericht news:LpHQd.407506$8l.401215@pd7tw1no... Wim Roffil wrote: Hi,
When I do a select with a limit I get always the same records.
Usually this is the desidered effect.
But now I want to do a random select. So every time I do a select
I should get a different set of results.
What is the best way to achieve this effect?
Thanks, Wim
What is your problem? Do you really want random records, or are you bothered that you get the same records everytime you perform a
select? Thank you for your reply.
I need reaaly random records. From a big collection I want to show
the visitors of my webpage just 5 or 10. Because adjacent records may be
related they should be spread over the whole collection. AUTO_INCREMENT is
not an option: it is not already there and the query is not over the whole
table but over a part of it (there is a WHERE clause).
If its the latter, you should use a WHERE clause in your SELECT and perhaps also a LIMIT start,rows
Thus,something like
SELECT firstname,lastname FROM myTable WHERE ID>10 LIMIT 5,12
will find all records that have ID>10 and return 12 records,
starting from the 5th one found (thus something like records with ID 15 to
27). If you want to read random records, request a random record (I'm assuming you've got a column/cell that is AUTO_INCREMENT that you
could use as reference).
Does that help you any? randelld This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rahul Anand |
last post by:
Hi all,
I am trying to fetch 5 records, randomly picked and in random order
from a MySQL table (MySQL version > 3.23).
I wrote my SQL Query as
SELECT name,id FROM tablename WHERE active =...
|
by: Christopher Brandsdal |
last post by:
Hi!
I'm not sure, but this might be a question not right for this group.
Problem:
I have a sql statement that selects all rows with a sertain criteria, an
display it on a page.
What I need...
|
by: Joseph Shraibman |
last post by:
Is there a way to get random rows besides ORDER BY random()? The problem with ORDER BY
random() is that is has to get all the rows from the table before the results are returned.
...
|
by: Jean-Francois.Doyon |
last post by:
Hello,
I'm trying to retrieve a limited number of random rows, and order them by a
column, and am not having any luck with that last part:
SELECT * FROM tablename ORDER BY random(), id LIMIT...
|
by: Ini |
last post by:
Hi,
Is there an easy way to pick at random one record out of a recordset and
then leave this recordset?
I was thinking about doing a recordcount of the recordset, then find at
random the...
| |
by: Arnau Rebassa |
last post by:
Hi everybody,
I'm doing the following query:
select * from messages order by random() limit 1;
in the table messages I have more than 200 messages and a lot of times, the
message retrieved...
|
by: Kari Lavikka |
last post by:
Hi!
I have to select a random row from a table where primary key isn't
continuous (some rows have been deleted). Postgres just seems to do
something strange with my method.
--
-- Use the...
|
by: darrel |
last post by:
I can grab a random number in vb.net like this:
Dim RandomClass As New Random
Dim RandomNumber As Integer
RandomNumber = RandomClass.Next(1, 26)
However, what I want is a random number. Short...
|
by: Jimmy |
last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far:
<%
Dim oConn, oRS, randNum
Randomize()
randNum = (CInt(1000 * Rnd) + 1) *...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |