Query to find matching rows in sql.

  • hello-

    I'm working with a database that contains a table with IDs to create Relationships and Reciprocal records in the database. The table with the IDs for the Relat and Recip values look like this:

    UniqueID RelatID RecipID

    21 1 2

    22 2 1

    53 3 8

    54 4 7

    55 5 9

    96 6 9

    97 7 4

    My goal is to find the "matching" rows, which in the example above would be Rows with the UniqueID 21, 22 (they "match" based on the RelatID/RecipID 1-2 and 2-1) and 54 and 97 (they matched on the RelatID/RecipID 4-7 and 7-4) Potentially, I would like to leave only 1 of the matching rows, so my final table would be: (eliminate rows with uniqueId 22 and 97)

    UniqueID RelatID RecipID

    21 1 2

    53 3 8

    54 4 7

    55 5 9

    96 6 9

    any help will be greatly appreciated!

    thank you!!

  • Answered over here.

    http://www.sqlservercentral.com/Forums/Topic1147880-131-1.aspx

    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

Viewing 2 posts - 1 through 1 (of 1 total)

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