Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    1

    Unanswered: Duplicated Data in different rows

    Hi everyone im trying to delete some duplicated data on my query but i dont know how to do it for example i got this result of my query:

    data1 | data2
    -------+--------
    1 | 2
    2 | 1


    and I only want (1, 2) not the (2, 1) because is the same data how could I do to erase this duplicates thanks.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Code:
    DELETE FROM the_table_with_no_name
    WHERE data1 = 1 and data2 = 2
    If you ask incomplete quesions you'll get incomplete answers.

  3. #3
    Join Date
    Aug 2009
    Location
    Olympia, WA
    Posts
    337
    Come on shammat, don't lead the guy astray. Clearly the answer is:
    Code:
    DELETE FROM the_table_with_no_name
    WHERE data1 = 2 AND data2 = 1

  4. #4
    Join Date
    Aug 2009
    Location
    Olympia, WA
    Posts
    337
    But a little more seriously, it looks like you are modelling some sort of relationship. When 1 becomes friends with 2, 2 is automatically friends with 1. So if you want to maintain consistency, add a check constraint that data1 < data2.

Posting Permissions

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