Selecting random

  • Hi all.

    Can anyone tell me if its possible to select 4 random rows from a table?

    Many thanks.

  • Sure its possible.

    Nearly anything is possible.

    But not as straightforward as a simple query.

    What are you looking for.

  • 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.

  • how about

    select top 4 * from table order by newid()

  • 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.

  • select top 4

    a.*

    from

    (...query to select top 10, whatever that is...) a

    order by

    newid()

  • Try using RANK() function , this might help.

  • Brilliant guys.

    Thanks for the help, much appreciated.

  • 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