I need to find matching values in two columns in same table, but with different rows.

| id | b | c |

| 1 | 2 | 3 |

| 2 | 2 | 4 |

| 3 | 2 | 5 |

| 4 | 2 | 1 |

| 5 | 3 | 1 |

| 6 | 6 | 1 |

| 7 | 7 | 1 |

| 8 | 8 | 1 |


what i want is value 3 is in both columns

Please Help!

有帮助吗?

解决方案

Try this self join:

SELECT DISTINCT t.b
FROM your_table t
INNER JOIN your_table s
ON t.b = s.c
AND t.id <> s.id
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top