This query is something about connecting between two ids in just one table.
Table: employer
Employee no. Lastname Firstname reports to title
111 Garret Mike 333 sales manager
333 Frank Savage 444 President
My question is how do I connect this table?
The table should be like:
Employee no. Lastname Firstname reports to(Supervisor No.) Firstname Lastame
111 Garret Mike 333 Frank Savage
I tried:
Select Employee no., Lastname, Firstname, reports to AS SuperVisorNumber, firstname, lastname From Employer
Where Employer.reports to =Employeeno.reports to
This is just an example. Don’t worry about the misspelling and everything.
You will need to join the table to itself:
See SQL Fiddle with Demo
If you want to see all employees, including the president, then change it to a
LEFT JOIN:See SQL Fiddle with Demo
If, you want to use more descriptive table aliases, then you can use something like this: