I'm new to working with db's and for practice I created a simple database called "Company", with three tables: employee, department, position. The fields in the employee table are: id, name, dept\_id, pos\_id and am using foreign keys to relate department and position to employee.

I'd like to display the information like this: 

```
Department 1
Directors: Kevin, Jane, Tom
Managers: Joe, Fred, Mary

Deparment 2
Directors: Bill, Elizabeth, Frank
Managers: Jennifer, Brian, Nicole

```

I used a JOIN statement to return all employees with their related positions and departments, but I can't figure out the correct PHP to display them like the example above. Should I have not used JOINS?

SQL: 

```
$sql = "SELECT employee.name, position.pos_name, department.dept_name 
        FROM employee
        INNER JOIN position
        ON employee.pos_id = position.id
        INNER JOIN department
        ON employee.dept_id = department.id";

    $result = $dbconn->query($sql);

```

Any help would be great,

Thanks