-4

Actually I don't have the idea that whether I should use some technique in storing data so that I can fetch according to my requirement or just need to search a query returning data according to my requirement. I want to store some data that is linked with eachother some rough data is given below

Name    Reference   City

Mian    Null    GUj

Hamza   Mian    Khi

Adam    Mian    Lhr

Jamil   Adam    Lhr

Musa    Jamil   Khi

Subhan  Musa    ISL

I want the solution that when I enter some name its fetches data of that person and its all childs and sub childs.

Ex: If I enter Adam acoording to above table info it should return Adam, Jamil, Musa, Subhan.

  • 1
    Please keep in mind we are all volunteers here spending our free time. We answer when we have time, not because you need something ASAP. – rene Apr 12 '17 at 19:28
  • Please don't spam the tags. This question has nothing to do with MVC or data structures. It isn't clear how this is related to C# and EF, either. –  Apr 12 '17 at 19:28
  • You use the phrase "according to my requirement" twice in your question without describing what those requirements are. –  Apr 12 '17 at 19:30
  • Dear Amy i have described it too clearly that i want to search this data form database so that if i enter some persons name to it fetches data from db in such a way that it also have all the childs and subchilds i also have the dummy data in the form of table please suggest me something i m trying really hard to achieve this output but could do that – Mian Ameer Hamza Apr 13 '17 at 07:33

1 Answers1

0

Well you must have a foreign key for the parent.

Here is an example

select * from person parent
left join person child on child.Parent_ID = parent.ID
where parent.Name like 'Adam'

I think this should work for you, you could also left join the sub children of the sub children.

Or you can write query that search recursive.

Please see this article for more info

recursive-select

Community
  • 1
  • 1
Alen.Toma
  • 4,684
  • 2
  • 14
  • 31