here is a link, which will give you idea about the algorithms of Breadth-First search,
http://en.wikipedia.org/wiki/Breadth-first_search[
^]
modify it according to your problem.
(your question is not much clear, post some codes, your table structure and then ask explain how the results should be)