Home » RDBMS Server » Server Administration » wanna print emp name and manager under which he is working..
wanna print emp name and manager under which he is working.. [message #374194] Wed, 30 May 2001 01:33 Go to next message
sweta
Messages: 19
Registered: May 2001
Junior Member
EMPNO ENAME JOB MGR
------ ---------- --------- ---------
7369 SMITH CLERK 7902
7499 ALLEN SALESMAN 7698
7521 WARD SALESMAN 7698
7566 JONES MANAGER 7839
7654 MARTIN SALESMAN 7698
7698 BLAKE MANAGER 7839
7782 CLARK MANAGER 7839
7788 SCOTT ANALYST 7566
7839 KING PRESIDENT
7844 TURNER SALESMAN 7698
7876 ADAMS CLERK 7788
7900 JAMES CLERK 7698
7902 FORD ANALYST 7566
7934 MILLER CLERK 7782

how do i prin the emp no and name and managers name under which he is working....
Re: wanna print emp name and manager under which he is working.. [message #374196 is a reply to message #374194] Wed, 30 May 2001 02:47 Go to previous messageGo to next message
Martin
Messages: 83
Registered: February 2000
Member
Use a self-join

select a.empno , a.ename as employee, b.ename as manager from emp a , emp b where a.mgr = b.empno
/
thanks but how it is working? [message #374199 is a reply to message #374194] Wed, 30 May 2001 04:06 Go to previous messageGo to next message
sweta
Messages: 19
Registered: May 2001
Junior Member
martin,

will u tell me, how this procedure will execute... i mean i have got the desired result which i wanted... but i am not been able to understand as how this will actually execute?
will u pls tell me that?
sweta
Re: thanks but how it is working? [message #374202 is a reply to message #374194] Wed, 30 May 2001 08:54 Go to previous message
Martin
Messages: 83
Registered: February 2000
Member
Taken from oracle 8i docs

Joins

A join is a query that combines rows from two or more tables, views, or materialized views ("snapshots"). Oracle performs a join whenever multiple tables appear in the query's FROM clause. The query's select list can select any columns from any of these tables. If any two of these tables have a column name in common, you must qualify all references to these columns throughout the query with table names to avoid ambiguity.

Join Conditions
Most join queries contain WHERE clause conditions that compare two columns, each from a different table. Such a condition is called a join condition. To execute a join, Oracle combines pairs of rows, each containing one row from each table, for which the join condition evaluates to TRUE. The columns in the join conditions need not also appear in the select list.

To execute a join of three or more tables, Oracle first joins two of the tables based on the join conditions comparing their columns and then joins the result to another table based on join conditions containing columns of the joined tables and the new table. Oracle continues this process until all tables are joined into the result. The optimizer determines the order in which Oracle joins tables based on the join conditions, indexes on the tables, and, in the case of the cost-based optimization approach, statistics for the tables.

In addition to join conditions, the WHERE clause of a join query can also contain other conditions that refer to columns of only one table. These conditions can further restrict the rows returned by the join query.

Self Joins

A self join is a join of a table to itself. This table appears twice in the FROM clause and is followed by table aliases that qualify column names in the join condition. To perform a self join, Oracle combines and returns rows of the table that satisfy the join condition.
Previous Topic: wanna print emp name and manager under which he is working..
Next Topic: CHECK constraint question
Goto Forum:
  


Current Time: Wed Jul 03 18:11:01 CDT 2024