Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2015
    Posts
    27

    Unanswered: removing duplicates records from a column pouplate randomly

    I ran this query to populate a field with random numbers but it keeps populating with some duplicate records. Any idea how I can remove the duplicates?

    UPDATE APRFIL
    SET ALTATH = CONVERT(int, RAND(CHECKSUM(NEWID())) * 10000);

    Below are sample output that I need the dupes not show. The table already exist and its sql 2008
    155957
    155957
    155968
    155974
    155976
    15599
    155990
    155997
    155997
    156005
    156008

  2. #2
    Join Date
    Jan 2015
    Posts
    27

    Post removing duplicates records from a column pouplate randomly

    I ran this query to populate a field with random numbers but it keeps populating with some duplicate records. Any idea how I can remove the duplicates?

    UPDATE APRFIL
    SET ALTATH = CONVERT(int, RAND(CHECKSUM(NEWID())) * 10000);

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    If you populate a column with random numbers, statistically you guarantee duplicates once you have enough rows. If you populate 100 rows with random numbers between 0 and 9, you are going to have duplicate values! Even if you have fewer rows than possible values, you will probably still have duplicates.

    Is your problem something more like needing 10000 values in random order than the problem is like having 10000 random numbers? These are two similar but definitely different problems.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •