Results 1 to 2 of 2

Thread: Recursive MySQL

  1. #1
    Join Date
    Jan 2013

    Recursive MySQL

    Well on a side note this is my first post, but seems like an excellent community. Now onto business...

    I've looked around at several approaches, but basically I have a table of employees, and one column stores a supervisor ID. For example:

    ID LastName FirstName Department Manager Title
    1 Smith John Administration President
    2 Johnson Sally Administration 1 Secretary
    3 Waters Andrew HR 1 HR Manager
    4 McNally Kevin Sales 1 VP, Sales
    5 Watson Adam Sales 4 Sales Associate
    5 Wilkinson Mary Sales 4 Sales associate

    I am working on an application for mangers to login and view employee information. I could easily get it working for a manger to view employees directly beneath, but I would like managers to view ALL employees under him. For example, John Smith should see those records of people who directly report to him, but also those that report to people who directly report to him. In this example, John Smith should have access to ALL records. I am using PHP and MySQL, and just can not grasp the SQL queries behind this one. I can imagine using recursion somehow, but i'm fairly new to this.

    Thank you!

  2. #2
    Join Date
    Aug 2004
    Managing hierarchical data in MySQL

    (There's a fair bit to consume there, but it does a good job of explaining the 2 main options and their pros and cons.)
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center