Hello,
I have a MySQL database with 3 tables. Each table contains a list of persons, and each table represents the level of a person. For example, tbl_level1_p, tbl_level2_p and tbl_level3_p. Level 1 persons have level 2 persons under them, and level 2 persons have level 3 persons under them. So, basically i neend to get a full list in an output form like this:
->Level 1 person data
->Level 2 person data
->Level 3 person data
->Level 3 person data
->Level 3 person data
->Level 2 person data
->Level 3 person data
->Level 3 person data
Then it does the same for next persons. What i got now is like 3 query loops:
SELECT * FROM tbl_level1_p
loop through tbl_level1_p
SELECT * FROM tbl_level2_p WHERE dataFromTbl1=something
loop through tbl_level2_p
SELECT * FROM tbl_level3_p WHERE dataFromTbl2=something
loop through tbl_level3_p
show data
end loop through tbl_level3_p
end loop through tbl_level2_p
end loop through tbl_level1_p
At this point it's hell lot of a loops and selects, and it is a bit too slow because the result set is quite large. Since i'm not that good with MySQL yet, i would like to know is if there is a better solution to this? Like, one advanced query, or maybe subselects, views, stored procedures, anything?
Thanks