Top Banner
56

Notice that No where clause In the syntax.

Dec 17, 2015

Download

Documents

Julius Elliott
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Notice that No where clause In the syntax.
Page 2: Notice that No where clause In the syntax.
Page 3: Notice that No where clause In the syntax.
Page 4: Notice that No where clause In the syntax.
Page 5: Notice that No where clause In the syntax.
Page 6: Notice that No where clause In the syntax.
Page 7: Notice that No where clause In the syntax.

Notice that No where clause In the syntax

Page 8: Notice that No where clause In the syntax.
Page 9: Notice that No where clause In the syntax.
Page 10: Notice that No where clause In the syntax.

Equijoins sometimes called

Simple or inner join

We can use column alias to recognize between columns have same name from two different

tables.

Page 11: Notice that No where clause In the syntax.
Page 12: Notice that No where clause In the syntax.
Page 13: Notice that No where clause In the syntax.
Page 14: Notice that No where clause In the syntax.
Page 15: Notice that No where clause In the syntax.
Page 16: Notice that No where clause In the syntax.
Page 17: Notice that No where clause In the syntax.
Page 18: Notice that No where clause In the syntax.
Page 19: Notice that No where clause In the syntax.

Join conditions containing something other than equality operation (operator) never use = sign

Page 20: Notice that No where clause In the syntax.
Page 21: Notice that No where clause In the syntax.
Page 22: Notice that No where clause In the syntax.

NoteNote::

Can’t use the IN operator or be linked to another condition by the OR operator.

Page 23: Notice that No where clause In the syntax.

Note that department_name Contracting is retrieved although it has no department_id

Page 24: Notice that No where clause In the syntax.

Note that last_name Grant is retrieved although it has no department_id or departmant_name

Page 25: Notice that No where clause In the syntax.
Page 26: Notice that No where clause In the syntax.
Page 27: Notice that No where clause In the syntax.
Page 28: Notice that No where clause In the syntax.
Page 29: Notice that No where clause In the syntax.

• Hierarchical queries are closely related to self- joins. You can use self-joins to see who is someone's direct manager. With hierarchical queries you can see not only the direct manager, but also who that manager works for, and so on.

• This lesson defines and gives examples of hierarchical queries.

• Using hierarchical queries, you can build an organization chart showing the structure of a company or a department.

• You can also use hierarchical queries to build a family tree with the eldest members of the family found close at the base or trunk of the tree and the youngest members representing branches of the tree. Branches can have their own branches, and so on.

Page 30: Notice that No where clause In the syntax.

HIERARCHICAL QUERIES• hierarchical queries have their own new

keywords:

START WITH, CONNECT BY PRIOR, and LEVEL.

• START WITHSTART WITH is used to tell Oracle which row to use as its Root of the tree it is constructing

• CONNECT BY PRIORCONNECT BY PRIOR tells Oracle how to do the inter-row joins

• LEVELLEVEL is how many steps down from the top of the tree we have taken.

Page 31: Notice that No where clause In the syntax.
Page 32: Notice that No where clause In the syntax.
Page 33: Notice that No where clause In the syntax.

LEVELLEVEL is a pseudo-column used with hierarchical queries, and it counts the number of steps it has taken from the root of the tree.

Page 34: Notice that No where clause In the syntax.

If you wanted to create a report displaying company management levels, beginning with the highest level and indenting each of the following levels, then this would be easy to do using the LEVEL pseudo column and the LPAD function to indent employees based on their level.

Page 35: Notice that No where clause In the syntax.

So if you wanted to just not include a single row in your result you would use the WHERE clause to exclude that row, but in the result it would then look like Gietz worked directly for Kochhar, which he does not.

Page 36: Notice that No where clause In the syntax.

• What is wrong in the following What is wrong in the following statement: statement:

SELECT last_name, department_id, salary

FROM employees

START WITH last_name = 'King'

CONNECT BY PRIOR manager_id = employee_id;

Page 37: Notice that No where clause In the syntax.
Page 38: Notice that No where clause In the syntax.
Page 39: Notice that No where clause In the syntax.
Page 40: Notice that No where clause In the syntax.
Page 41: Notice that No where clause In the syntax.
Page 42: Notice that No where clause In the syntax.

Note never use TABLE alias with USING clause

Page 43: Notice that No where clause In the syntax.

The column used in USING clause not necessary to be in select clause

Page 44: Notice that No where clause In the syntax.
Page 45: Notice that No where clause In the syntax.

Join using ON to specify the condition or the column used

Page 46: Notice that No where clause In the syntax.

Observe the employee_id column and the manager_id column

Page 47: Notice that No where clause In the syntax.
Page 48: Notice that No where clause In the syntax.
Page 49: Notice that No where clause In the syntax.
Page 50: Notice that No where clause In the syntax.
Page 51: Notice that No where clause In the syntax.
Page 52: Notice that No where clause In the syntax.
Page 53: Notice that No where clause In the syntax.
Page 54: Notice that No where clause In the syntax.
Page 55: Notice that No where clause In the syntax.

Number of rows returned in inner join was

19 rows19 rows

In left outer join and right outer join was

20 rows20 rows

While in full outer join is

21 rows21 rows

Page 56: Notice that No where clause In the syntax.

GOOD LUCK

SEE YOU NEXT MEETING

Raafat [email protected]

[email protected]