Get Random Records from a Table (Sybase)

To get random records from a table in Sybase, you can use NEWID() function in ORDER BY clause. The function returns a unique and random global identifier (GUID). Example:

SELECT TOP 100 * FROM dbo.Data ORDER BY NEWID()
Advertisements
This entry was posted in Sybase, T-SQL. Bookmark the permalink.

3 Responses to Get Random Records from a Table (Sybase)

  1. Mike says:

    Hi, this works fine but with large amounts of data (lets say over 5 millons of records) it performs too slow. Many minutes to execute. Any other sugestion?

  2. Aleksandr says:

    I agree with Mike. It takes a lot of time wirking with large tables!

  3. Raghu says:

    How to get random samples from a table . Suppose I got 2 columns one contains duplicate values column A and and other unique COLUMN B Now for each unique vale in A I NEED 10 records randomly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s