Monday, August 30, 2021

Joining Multiple Tables in SQL: Best Practices and Techniques

SQL JOINS :
  •  Sometimes we have to combine the data from so many tables.
  •  A join combines the data spread across tables.
  •  A join is performed by the 'where' clause which combines the specified rows of tables.
  •  A common column provides the join condition.

Types of joins :
 There are three types of joins. They are
  1. Simple join or inner join
  2. Self join
  3. Outer Join

1. Inner join
  •   The most important and frequently used of the joins is the inner join.
  •   They are also referred to as EQUIJOIN.
  •   Inner join retrieve only the 'MATCHED RECORDS'.

Example :
  select e.employee_id,e.first_name,e.department_name,d.department_id
  from employees e, departments d
  where e.department_id = d.department_id;
  
 Non-equijoin
  •   A join that is based on relational operators other than = is called a non-Equi join.
Example :
  select a.item_id,item_name,stock,quantity
  from item_master a,sales_details b
  where(a.item_id=b.item_id)
  and (a.stock<b.quantity);

  This statement lists all items for which the stock in hand is less than the quantity ordered.

2. Outer Join
  •    The outer join extends the result of a simple join.
  •    An outer join returns all the rows from one table that do not match any row from the other table.
  •    The symbol + is used to represent the outer join.

 Left Outer Join
  •    All the records from the left side table and only the matched rows join from the right side table.

 Example :
   select e.employee_id,e.first_name,e.department_name,d.department_id
   from employees e, departments d
   where e.department_id = d.department_id(+);

 Right Outer Join
  •    All the records are from the right side table and only the matched rows left side table.

 Example :
   select e.employee_id,e.first_name,e.department_name,d.department_id
   from employees e, departments d
   where e.department_id(+) = d.department_id;

3. Self Join 
  •   Self-join is a regular join, but the table is joined with itself.

Saturday, August 28, 2021

The Complete Guide to Oracle Application R12 VIEWS

 Database Objects in Oracle :

1. TABLE:  Used to store information & allows manipulation, retrieval & share of information.

 ( user_tables, user_tab_columns ,TAB )

2. VIEWS & SYNONYMS: Used to manipulate, retrieve &  share information. They will not hold data.
 ( user_views, user_synonyms, CAT )

3. SEQUENCES: Used to generate the numbers automatically. 
( user_sequences )

4. INDEX & CLUSTER: Used to improve the performance of Oracle while retrieving or manipulating data.
 ( user_indexes , user_clusters )

Views: 
 It is a stored select statement.
 It is a virtual or Logical component.
 It allows Desc, DML, and Select on it.
 It will not hold data.
 It is stored permanently in the "User_views" system table.
 It can be shared with other users.

 DML on view are reflected in Table and DML on   Table are reflected in the view.

 * It is used to share "Selected Rows and Columns"   with other users. It is used for reporting purposes.
 *It will Improve performance while manipulating or retrieving data from the Views.