January 21, 2009 at 8:48 am
Hi all.
Can anyone tell me if its possible to select 4 random rows from a table?
Many thanks.
January 21, 2009 at 8:50 am
Sure its possible.
Nearly anything is possible.
But not as straightforward as a simple query.
What are you looking for.
January 21, 2009 at 8:52 am
Hi there, thanks very much for the swift response.
Basically im looking to pull 4 random products from a product table, however these four products should be in the top 10 of the table. Does that make sense?
Cheers.
January 21, 2009 at 9:06 am
how about
select top 4 * from table order by newid()
January 21, 2009 at 9:10 am
Hi mate, cheers for the reply.
Is it not the case that would bring back a random 4 rows but not necessarily from the top 10?
Cheers.
January 21, 2009 at 9:14 am
select top 4
a.*
from
(...query to select top 10, whatever that is...) a
order by
newid()
January 21, 2009 at 9:15 am
Try using RANK() function , this might help.
January 21, 2009 at 9:18 am
Brilliant guys.
Thanks for the help, much appreciated.
January 21, 2009 at 9:22 am
Can you please explain your situation better.
what do you mean top 10? The first 10 records in the table,
The top 10 highest quantity? How do you define this?
Please post DDL and Data scripts creating a table and data statements.
along with an example of what you would like the data to look like.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply