Skip to content
Advertisement

Find records which cross-reference each other

I want to extract all the rows from a database table, where the rows cross-reference each other.

My table contains 2 rows: ref1 & ref2

Table example:

In this case, I want my query to return only rows 01 and 03, because they cross-reference each other.

Is this possible using a single query, or will I need to iterate the entire table manually?

I’m using MySQL.

Advertisement

Answer

A simple JOIN can do that in a straight forward manner;

An SQLfiddle to test with.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement