Presentation is loading. Please wait.

Presentation is loading. Please wait.

New SQL Commands in Oracle. INNER JOINs NATURAL JOIN Perform JOIN based on like columns in two tables. The Like columns must be of the same name and data.

Similar presentations


Presentation on theme: "New SQL Commands in Oracle. INNER JOINs NATURAL JOIN Perform JOIN based on like columns in two tables. The Like columns must be of the same name and data."— Presentation transcript:

1 New SQL Commands in Oracle

2 INNER JOINs NATURAL JOIN Perform JOIN based on like columns in two tables. The Like columns must be of the same name and data type. ON clause is not required Natural Join SELECT* FROMCust NATURAL JOIN Emp;

3 USING Perform JOIN based on specified columns in two tables. The specified columns must have the same name and data type. With “Using” SELECT* FROMCust JOIN Emp USING (city, age); // This join is also called COLUMN name join in that it uses // only column names specified in USING clause Without “Using” SELECT* FROMCust, Emp WHERECust.city = Emp.City AND Cust.age= Emp.Age;

4 ON Perform JOIN based on specified columns in two tables. Can be used for columns having different names With “ON” SELECT * FROM Cust JOIN Emp ON Cust.cust_city=Emp.emp_city; // This join is called CONDITION JOIN SELECT* FROMCust JOIN Emp ON(Cust.city = Emp.city AND Cust.age > Emp.age);

5 Without “ON” SELECT * FROM Cust, Emp WHERE Cust.cust_city=Emp.emp_city; SELECT* FROMCust, Emp WHERE(Cust.city = Emp.city AND Cust.age > Emp.age);

6 CROSS JOIN Produces cross product of two tables, resulting in a Cartesian join // With CROSS JOIN (On and Using clauses are not allowed) SELECT* FROMCust CROSS JOIN Emp; // Without CROSS JOIN SELECT* FROMCust, Emp;

7 OUTER JOIN All the above joins are called INNER JOINs. (a) LEFT OUTER JOIN (all tuples in the left table are kept) SELECT * FROMCustLEFT OUTER JOIN Emp Using (city); SELECT * FROMCustLEFT OUTER JOIN Emp ON (Cust.city = Emp.City); (b) RIGHT OUTER JOIN (all tuples in right table are kept) SELECT * FROMCustRIGHT OUTER JOIN Emp Using (city); (c)FULL OUTER JOIN SELECT * FROMCustFULL OUTER JOIN Emp Using (city);

8 CASE Statement Simple CASE Statements SELECT Fname, Lname, (CASE DNO WHEN1 THEN‘Headquarters’ WHEN4THEN‘Administration’ WHEN5THEN ‘Research’ ELSE‘No department’ END) AS Department FROMEmployee; Fname,LnameDepartment John SmithResearch FranklinWongResearch Alica ZelayaAdministration

9 Searched CASE Statements SELECT Fname, Lname, Salary (CASESalary WHENSalary <= 25000 THEN 1500 WHENSalary > 25000 AND Salary < 50000THEN 1000 WHENSalary > 50000 AND Salary < 100000 THEN 500 ELSE 0 END) “Bonus” FROMEmployee; Fname,LnameSalary Bonus John Smith300001000 FranklinWong400001000 Alica Zelaya250001500


Download ppt "New SQL Commands in Oracle. INNER JOINs NATURAL JOIN Perform JOIN based on like columns in two tables. The Like columns must be of the same name and data."

Similar presentations


Ads by Google