DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: oracle 9i sql question

  1. #1
    Join Date
    Nov 2006
    Location
    1038 khatiwala tank ,indore,mp
    Posts
    2

    oracle 9i sql question

    hello,
    i want to know that hw to select & delete duplicate rows from a table?

  2. #2
    Join Date
    Nov 2006
    Posts
    21
    in both select and delete, the duplicate rows are processed.

    You can use the DISTINCT keyword to surpress the duplicate rows in select.
    E.g:

    Select DISTINCT last_name from employees;

  3. #3
    Join Date
    Nov 2006
    Posts
    4
    But how would select distinct know how may duplicate records exist and which particular ones to delete and which to keep. The best approach would be to count and then group the duplicates so say you have data.

    a b c
    = = =
    1 a 1
    1 a 1
    2 b 2
    2 b 2
    2 b 2
    3 b 3

    Select distinct will bring back
    SELECT
    DISTINCT
    a,
    b,
    c
    FROM A

    a b c
    = = =
    1 a 1
    2 b 2
    3 b 3

    but record 3 b 3 is not a duplicate. in this case a group by aggregate e.g.

    SELECT
    a,
    b,
    c,
    count(1)
    FROM a
    GROUP BY
    a, b, c
    having count(1) > 1

    will return everything with more than 1 row.

    a b c count(1)
    = = = =
    1 a 1 2
    2 b 2 3

    You can then formulate you next step using this result. If anyone has a simpler way let me know

Posting Permissions

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


Click Here to Expand Forum to Full Width