We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Explanation:
It's not much tricky with few pitfalls to avoid we can solve it easily by two approaches, one by the use of CROSS JOIN and a simple INNER JOIN. The cte here, allocating a unique row number to each row, is to avoid joining a row with itself which may happen here as the rows are coming from the same tables, here cte. The outer most select clause just after the cte definition is to avoid redundancy which may arise due to both the ctes having the values of {x<sub>1</sub>, y<sub>1</sub>} and {x<sub>2</sub>, y<sub>2</sub>} . So, a row which is to be present in the output table which was join by x<sub>1</sub> = y<sub>2</sub> and y<sub>1</sub>} = x<sub>2</sub> can again appear by the y<sub>2</sub> = x<sub>1</sub> and x<sub>2</sub> = y<sub>1</sub>} .
Symmetric Pairs
You are viewing a single comment's thread. Return to all comments →
Explanation: It's not much tricky with few pitfalls to avoid we can solve it easily by two approaches, one by the use of
CROSS JOIN
and a simpleINNER JOIN
. The cte here, allocating a unique row number to each row, is to avoid joining a row with itself which may happen here as the rows are coming from the same tables, here cte. The outer most select clause just after the cte definition is to avoid redundancy which may arise due to both the ctes having the values of{x<sub>1</sub>, y<sub>1</sub>}
and{x<sub>2</sub>, y<sub>2</sub>}
. So, a row which is to be present in the output table which was join byx<sub>1</sub>
=y<sub>2</sub>
andy<sub>1</sub>}
=x<sub>2</sub>
can again appear by they<sub>2</sub>
=x<sub>1</sub>
andx<sub>2</sub>
=y<sub>1</sub>}
.MySQL Code: