-2
I have two tables in my database, one containing all users with id and name and other details, and another table containing all work cells, where tie through the user id who is the leader and who is the supervisor in the cell.
Each cell has 1 leader and 1 supervisor, both fields (columns in the table of cells) have as value the number of the numerical index that references the table of users (foreign key that identifies the leading user, and the user that is the supervisor of the cell).
To know therefore who is the leader of the cell, use the value stored in the leader_id column as the search key in the users table. And the same for supervisor (using the supervisor_id field as the search key in the users table).
I would like to create an SQL query that returns the result as follows, using the values of these two tables as parameter:
Can anyone help me with this SQL search?
we can help, you can show how far you’ve come with the query?
– Ricardo Pontual
I was able to do this query: SELECT * FROM Cells INNER JOIN users ON Cells.leader_id = users.id; however, I’m only able to return one of the columns (either using leader_id or supervisor_idas reference only). However in the result I need the column with the name of the leader and supervisor, because I will pass the query to a view in Laravel...
– Fernando Ferrari Fernandes
Use two JOIN with the same users table, one to get the leader and one to get the supervisor.
– anonimo