Oracle SQL Query: Employees Managers & Supervisors

  • Thread starter Naeem
  • Start date
  • Tags
    Sql
In summary, the conversation discusses queries related to finding managers and supervisors in a company. The first query retrieves the names and department names of managers who do not supervise any employee. The second query finds supervisors but not managers, and the third query retrieves employees who are both managers and supervisors. There is also a suggestion to add an alias for the employee name column in the first query.
  • #1
Naeem
194
0
Hello,

I have written the below queries, can somebody tell me if they are correct. manager_id in Employee Table - supervisor ; manager_id in departments table - manager.

names and department names of managers who do not supervise any employee.

select e.first_name|| ' ' ||e.last_name employee_name,d.department_name
from employees e join departments d
on e.employee_id =d.manager_id
where e.employee_id not in(select manager_id from employees where manager_id is not null)

supervisors but not managers

select e.first_name|| ' ' ||e.last_name employee_name
from employees e where e.employee_id in(select manager_id from employees where manager_id is not null)
and e.employee_id in (select manager_id from departments where manager_id is not null);

Employees who are managers and supervisors.

select e.first_name|| ' ' ||e.last_name employee_name
from employees e where e.employee_id in(select manager_id from employees where manager_id is not null)
and e.employee_id in (select manager_id from departments where manager_id is not null);

Any feedback much appreciated.
 
Physics news on Phys.org
  • #2
Yes, the queries are correct. However, you may want to consider adding an alias for the employee name column. For example: select e.first_name|| ' ' ||e.last_name AS employee_name,d.department_namefrom employees e join departments don e.employee_id =d.manager_idwhere e.employee_id not in(select manager_id from employees where manager_id is not null)
 

Related to Oracle SQL Query: Employees Managers & Supervisors

What is an Oracle SQL query?

An Oracle SQL query is a command used to retrieve data from a relational database management system (RDBMS) called Oracle. It allows you to search, insert, update, and delete data from the database.

What is the purpose of the Employees Managers & Supervisors query?

The Employees Managers & Supervisors query is used to retrieve a list of all employees, their managers, and their supervisors from a company database. This information can be used for various purposes such as performance evaluations, team assignments, and reporting.

What are the main components of the Employees Managers & Supervisors query?

The main components of the Employees Managers & Supervisors query include the SELECT, FROM, and WHERE clauses. The SELECT clause specifies the data to be retrieved, the FROM clause identifies the tables from which the data will be retrieved, and the WHERE clause filters the data based on specific criteria.

How can I customize the Employees Managers & Supervisors query to fit my specific needs?

The Employees Managers & Supervisors query can be customized by adding additional clauses, such as ORDER BY or GROUP BY, to sort and group the data in a specific way. You can also use different conditions in the WHERE clause to filter the data based on your specific requirements.

Can I use the results of the Employees Managers & Supervisors query in other applications?

Yes, you can use the results of the Employees Managers & Supervisors query in other applications by exporting the data or using it as a data source. This allows you to further analyze and manipulate the data in tools such as Microsoft Excel or import it into other databases for further processing.

Similar threads

  • Set Theory, Logic, Probability, Statistics
2
Replies
67
Views
3K
  • Programming and Computer Science
Replies
7
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
9
Views
911
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
1
Views
892
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • STEM Career Guidance
Replies
11
Views
2K
Back
Top