I have a table with all of our users (nearly 2000 users):
username manager isvip
bob alice false
alice henry false
bart henry true
henry true
For Bob, I have to find Henry (because bob < alice < henry = vip).
I tried to do some loops to find the manager until the manager is a vip, but it is not optimized at all, and it is very long for 2000 users.
Can I find in an easy way in SQL + PHP the vip for a user?