Search code examples
cross-join

Following CROSS JOIN how to remove records comparing same record


I have done a CROSS JOIN, comparing each record to all other records.

However, I want to remove those where the same record is being compared.

What is the most efficient way to do this?


Solution

  • Is this what you are looking for?

    SELECT * 
    FROM Table1 
    CROSS JOIN Table2
    WHERE Table1.PrimaryKey <> Table2.PrimaryKey