random select

  • I would like to know how to select random records from data in both sql server 2005 standard edition.

  • can you please be more specific about what do you need to do?

  • there's a trick that you can get randomly ordered records by using the NEWID() function...is that what you are after?

    select top 10

    ColumnList

    From SomeTable

    order By NEWID()

    and this?

    in both sql server 2005 standard edition.

    in both SQL 2005 and what? oracle? sql 2008?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (5/27/2011)


    there's a trick that you can get randomly ordered records by using the NEWID() function...is that what you are after?

    select top 10

    ColumnList

    From SomeTable

    order By NEWID()

    and this?

    in both sql server 2005 standard edition.

    in both SQL 2005 and what? oracle? sql 2008?

    That's a very quick way of doing this.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • The method using NEWID works well.

    TABLESAMPLE is pretty handy too:

    http://technet.microsoft.com/en-us/library/ms189108.aspx

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply