I have two tables Table_Employee
,Table_Department
respectively, i wanted to select the manager who belongs to employee more than three times & also want to display depatment name along with it.
This task has to be done in a single query. Is it easy to do it ? here is my table structure .
here the Column_Empno will be the Column_Manager, which means the table is self reference
Table_Employee
Column_Empno int
Column_Fname varchar(50)
Column_Lname varchar(50)
Column_Job varchar(50)
Column_Manager int
Column_HireDate date
Column_Salary int
Column_Commision int
Column_DeptNo int
Table_Department
Column_DeptNo int
Column_Dname varchar(50)
Column_Location varchar(50)
Manager + Department:
SELECT Column_Fname, Column_Lname, table_Department.Column_Dname
FROM Table_Employee
INNER JOIN table_Department ON Table_Employee.Column_DeptNo = table_Department.Column_DeptNo
or you could also write:
SELECT Column_Fname, Column_Lname, table_Department.Column_Dname
FROM Table_Employee
WHERE Table_Employee.Column_DeptNo = table_Department.Column_DeptNo
It's not tested. By the way, why do you Name your Colums "Column_..." and not just "Fname", "Lname",... and your table "Table_...." and not just "Employee" and "Department"?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With