0

Possible Duplicate:
MySQL recursive tree search

I 'm putting a contacts searching option, so user would be able to search contacts upto 10 levels like, I can search a contact of my contact, and contact of his contact and so on upto 10 levels.

It can be done over too many sql joins but I want to know if there is some better solution for it

thanks

Edit: Here is the schema

User table id, username

contact table id, user_id, contact_id

both user_id and contact_id are FK of User table.

Here is the simple query upto 1 level to get my contacts

SELECT * FROM users LEFT JOIN contacts 
ON users.id = contacts.user_id
WHERE users.id = MY_USER_ID
Community
  • 1
  • 1
MZH
  • 1,414
  • 4
  • 29
  • 57

0 Answers0