I have a MySQL table called connections, with two unsigned integer fields, called a and b (which are unique), with the following values (and many more).
A, B
1, 2 1, 3 8, 9 4, 6 5, 1 3, 7
1 is connected to 2, 3, and 5. 3 is connected to 7. I have been struggling to come up with a query that will select all connections for a given number. For example, number 2 woul开发者_Go百科d return the following...
1
2 3 5 7
Number 5 would also return...
1
2 3 5 7
If someone can help me out I would greatly appreciate it. I have been stuck on this for the last week, and have made little to no progress. :(
Thanks in advance!
I don't think your problem cannot be solved with a single select statement. Solution requires multipass scan of your tables to arrive at the final answer
It sounds like you need a hierarchical query here, which exists in Oracle, but I don't think it is in mySql. Here is a link to an article which explains how to get hierarchical functionality in mySql. I have not tried it myself.
http://explainextended.com/2009/03/17/hierarchical-queries-in-mysql/
精彩评论