Presentation is loading. Please wait.

Presentation is loading. Please wait.

Notice that No where clause In the syntax.

Similar presentations


Presentation on theme: "Notice that No where clause In the syntax."— Presentation transcript:

1

2

3

4

5

6

7 Notice that No where clause In the syntax

8

9

10 Equijoins sometimes called Simple or inner join We can use column alias to recognize between columns have same name from two different tables.

11

12

13

14

15

16

17

18

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

20

21

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

23 Note that department_name Contracting is retrieved although it has no department_id

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

25

26

27

28

29 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.

30 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 LEVEL LEVEL is how many steps down from the top of the tree we have taken.

31

32

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

34 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.

35 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.

36 What is wrong in the following statement:What is wrong in the following statement: SELECT last_name, department_id, salary FROM employees START WITH last_name = 'King' CONNECT BY PRIOR manager_id = employee_id;

37

38

39

40

41

42 Note never use TABLE alias with USING clause

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

44

45 Join using ON to specify the condition or the column used

46 Observe the employee_id column and the manager_id column

47

48

49

50

51

52

53

54

55 Number of rows returned in inner join was 19 rows In left outer join and right outer join was 20 rows While in full outer join is 21 rows

56 GOOD LUCK SEE YOU NEXT MEETING Raafat Rashad raafat_rashad@yahoo.co.uk raafat_rashad@hotmail.com


Download ppt "Notice that No where clause In the syntax."

Similar presentations


Ads by Google