Search code examples
sqlsql-servert-sqlsubquery

columns referencing each other


Let's say there is a table that contains data rows as below.

enter image description here

As you see above, Applicant 79 has a twin 80 and Twin 80 has Applicant 79 as a twin.

Since ID 11 and 12 are really the same information, I am wishing to select a unique twin data as following.

enter image description here

How can I achieve this in SQL Server?

Thank you very much in advance.


Solution

  • You can simply do:

    select * from t where ApplicantId < TwinId