SlideShare une entreprise Scribd logo
1  sur  14
1 Using ORACLE® Retrieving data from multiple tables(joins) Sub-queries and Set operators
2 JOINS
3 USES OF JOINS
4 EQUI JOIN Equi Join is a simple SQL join condition that uses EQUAL sign as the comparison operator  Syntax: SELECT col1,col2,col3 FROM table1,table2 WHERE table1.col1=table2.col1; EQUI JOIN on product_master and customer_master tables: SELECT prod_name,prod_stock,quantity,deliver_by                     FROM product_master,customer_master  WHERE order_id=prod_id;  By this we can have an approximation of the quantity and date of products that need to be shipped out.
5 OUTER JOINS OUTER join condition returns all rows from both tables which satisfy the join condition along with rows which do not satisfy the join condition from one of the tables. The SQL outer join operator in Oracle is ( + ) and is used on one side of the join condition only. Syntax: SELECT col1,col2 FROM table1,table2 WHERE  table1.col1 (+) = table2.col1; OUTER JOIN on product_master table and customer_master: SELECTp.prod_id, p.prod_name, o.order_id, o.quantity FROM customer_master o, product_master p WHEREp.prod_id (+)= o.order_id  ;
6 CARTESIAN JOINS If a SQL join condition is omitted or if it is invalid the join operation will result in a Cartesian product. The Cartesian product returns a number of rows equal to the product of all rows in all the tables being joined. For example, if the first table has 20 rows and the second table has 10 rows, the result will be 20 * 10, or 200 rows. This query takes a long time to execute. SYNTAX: SELECT col1,col2 FROM table1,table2; CARTESIAN JOIN on product_master and customer_master: SELECTorder_id,prod_name FROMcustomer_master,product_master; Here  each row from customer_master will be  Mapped to each row of product_master.Here the This query contains 50 rows only 10 rows are  Shown in the figure
7 SELF JOINS A Self join is the type of SQL join where we join a particular table to itself. Here it is necessary to ensure that the join statement defines an ALIAS name for both the copies of the tables to avoid column ambiguity  Syntax for Table Alias: SELECTs.first_nameFROMstudent_details s;            In this query alias s is defined for the table student_details and the column first_name is selected from the table. Self Join on Course table: SELECTa.course_nameASCOURSE,b.course_nameAS PREREQUSITE_COURSE FROMcourse_ma,course_m b WHEREa.pre_course=b.course_id;
8 NATURAL/CARTESIAN  JOINS CARTESIAN JOIN is also known as NATURAL JOIN .The output of this join can be filtered using the WHERE clause. SELECTprod_ID,prod_name ,order_id,quantity FROM product_master NATURAL JOIN customer_master WHERE prod_name LIKE ('teak%') AND quantity=10;
9 SUBQUERY IN SQL A Subquery is also called as an Inner query or a Nested query. It is a query inside another query. A subquery is usually added in the WHERE Clause of the SQL statement. Most of the time, a subquery is used when we know how to search for a value using a SELECT statement, but do not know the exact value. Subqueries are an alternate way of returning data from multiple tables Subqueries can be used with the following sql statements along with the comparision operators like =, <, >, >=, <= etc. Usually, a subquery should return only one record, but sometimes it can also return multiple records when used with operators like IN, NOT IN in the where clause. 			 SELECT column….. FROM tablename WHERE SUBQUERY rown ……			The result set of the 			subquery act as the condition set for 				the main query 												 row1 The SELECT subquery statement
10 SET OPERATORS Set operators combine the results of two component queries into a single result. Queries containing set operators are called compound queries. The Set Operators in SQL are:
11 SET OPERATOR - UNION The UNION set operator is used to combine multiple subqueries and their outputs. The UNION clause merges the outputs of two or more subqueries into one in such a way that the  Result set = Records only in query 1 + Records only in query 2 + A single set of records 	  	    common to both query 1 and query 2 . Example: SELECT * FROM InfoTable  WHERE  age = 40			 UNION SELECT * FROM InfoTable  WHERE age = 45;  Result Set Records  from  Query 1 Records  from  Query 2 Query 1 Query 2 Records common to both Queries
12 SET OPERATOR - INTERSECT The INTERSECT set operator is used to combine multiple subqueries and their outputs. The INTERSECT clause merges the outputs of two or more subqueries into one in such a way that the  Result set = A single set of records common to both query 1 and query 2 . Example: SELECT * FROM InfoTable  WHERE  age = 40			 INTERSECT SELECT * FROM InfoTable  WHERE age = 45;  Result Set Records  from  Query 1 Records  from  Query 2 Query 1 Query 2 Records common to both Queries
13 SET OPERATOR - MINUS The MINUS set operator is used to combine multiple subqueries and their outputs. The MINUS clause filters records from Second Query and common records and displays the remaining records. Result set = Records only in query 1 – [ Records only in query 2 + A single set of records 	  	    common to both query 1 and query 2 ]. Example: SELECT * FROM InfoTable  WHERE  age = 40			 MINUS SELECT * FROM InfoTable  WHERE age = 45;  Result Set Records  from  Query 1 Records  from  Query 2 Query 1 Query 2 Records common to both Queries and from Query 2 not included in the result set
THANK YOU 14 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit:   www.dataminingtools.net

Contenu connexe

Tendances (20)

Sql joins
Sql joinsSql joins
Sql joins
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
 
Triggers
TriggersTriggers
Triggers
 
Subqueries
SubqueriesSubqueries
Subqueries
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
 
Sql joins
Sql joinsSql joins
Sql joins
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Sql select
Sql select Sql select
Sql select
 
SQL
SQLSQL
SQL
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Index in sql server
Index in sql serverIndex in sql server
Index in sql server
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 

En vedette

Oracle sql joins
Oracle sql joinsOracle sql joins
Oracle sql joinsredro
 
ANSI SQL Transparent Multipath Hierarchical Structured Data Processing for Re...
ANSI SQL Transparent Multipath Hierarchical Structured Data Processing for Re...ANSI SQL Transparent Multipath Hierarchical Structured Data Processing for Re...
ANSI SQL Transparent Multipath Hierarchical Structured Data Processing for Re...Michael M David
 
Sql Patterns
Sql PatternsSql Patterns
Sql Patternsphanleson
 
oracle joins and sql joins
oracle joins and sql joinsoracle joins and sql joins
oracle joins and sql joinsshripal singh
 
Something about oracle joins
Something about oracle joinsSomething about oracle joins
Something about oracle joinsmysqlops
 
Corba and-java
Corba and-javaCorba and-java
Corba and-javaafreen58
 
Step By Step How To Install Oracle XE
Step By Step How To Install Oracle XEStep By Step How To Install Oracle XE
Step By Step How To Install Oracle XEAchmad Solichin
 
Tutorial Instalisasi Oracle 10g dan Setting User
Tutorial Instalisasi Oracle 10g dan Setting UserTutorial Instalisasi Oracle 10g dan Setting User
Tutorial Instalisasi Oracle 10g dan Setting UserImam Halim Mursyidin
 
Intro oracle10gexpress
Intro oracle10gexpressIntro oracle10gexpress
Intro oracle10gexpressjatin Sareen
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinAjay Gupte
 
Oracle intro to designer abridged
Oracle intro to designer abridgedOracle intro to designer abridged
Oracle intro to designer abridgedFITSFSd
 
Sql server ___________ (advance sql)
Sql server  ___________  (advance sql)Sql server  ___________  (advance sql)
Sql server ___________ (advance sql)Ehtisham Ali
 
Time-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesTime-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesChema Alonso
 
Rmi, corba and java beans
Rmi, corba and java beansRmi, corba and java beans
Rmi, corba and java beansRaghu nath
 

En vedette (20)

Oracle sql joins
Oracle sql joinsOracle sql joins
Oracle sql joins
 
ANSI SQL Transparent Multipath Hierarchical Structured Data Processing for Re...
ANSI SQL Transparent Multipath Hierarchical Structured Data Processing for Re...ANSI SQL Transparent Multipath Hierarchical Structured Data Processing for Re...
ANSI SQL Transparent Multipath Hierarchical Structured Data Processing for Re...
 
Sql Patterns
Sql PatternsSql Patterns
Sql Patterns
 
SQL UNION
SQL UNIONSQL UNION
SQL UNION
 
Flash Presentation
Flash PresentationFlash Presentation
Flash Presentation
 
oracle joins and sql joins
oracle joins and sql joinsoracle joins and sql joins
oracle joins and sql joins
 
Something about oracle joins
Something about oracle joinsSomething about oracle joins
Something about oracle joins
 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
 
Hash join
Hash joinHash join
Hash join
 
Corba and-java
Corba and-javaCorba and-java
Corba and-java
 
Join operation
Join operationJoin operation
Join operation
 
Step By Step How To Install Oracle XE
Step By Step How To Install Oracle XEStep By Step How To Install Oracle XE
Step By Step How To Install Oracle XE
 
Tutorial Instalisasi Oracle 10g dan Setting User
Tutorial Instalisasi Oracle 10g dan Setting UserTutorial Instalisasi Oracle 10g dan Setting User
Tutorial Instalisasi Oracle 10g dan Setting User
 
Intro oracle10gexpress
Intro oracle10gexpressIntro oracle10gexpress
Intro oracle10gexpress
 
Intro to Application Express
Intro to Application ExpressIntro to Application Express
Intro to Application Express
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
 
Oracle intro to designer abridged
Oracle intro to designer abridgedOracle intro to designer abridged
Oracle intro to designer abridged
 
Sql server ___________ (advance sql)
Sql server  ___________  (advance sql)Sql server  ___________  (advance sql)
Sql server ___________ (advance sql)
 
Time-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesTime-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy Queries
 
Rmi, corba and java beans
Rmi, corba and java beansRmi, corba and java beans
Rmi, corba and java beans
 

Similaire à Retrieving data and combining results in ORACLE

Similaire à Retrieving data and combining results in ORACLE (20)

Query
QueryQuery
Query
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 
Sql joins
Sql joinsSql joins
Sql joins
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
Interacting with Oracle Database
Interacting with Oracle DatabaseInteracting with Oracle Database
Interacting with Oracle Database
 
Computer Science:Sql Set Operation
Computer Science:Sql Set OperationComputer Science:Sql Set Operation
Computer Science:Sql Set Operation
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Babitha2.mysql
Babitha2.mysqlBabitha2.mysql
Babitha2.mysql
 
Babitha2 Mysql
Babitha2 MysqlBabitha2 Mysql
Babitha2 Mysql
 
e computer notes - Advanced subqueries
e computer notes - Advanced subqueriese computer notes - Advanced subqueries
e computer notes - Advanced subqueries
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 
SQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxSQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptx
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 

Plus de oracle content

Plus de oracle content (13)

Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Oracle : DML
Oracle : DMLOracle : DML
Oracle : DML
 
Oracle: Programs
Oracle: ProgramsOracle: Programs
Oracle: Programs
 
Oracle: Commands
Oracle: CommandsOracle: Commands
Oracle: Commands
 
Oracle:Cursors
Oracle:CursorsOracle:Cursors
Oracle:Cursors
 
Oracle: Control Structures
Oracle:  Control StructuresOracle:  Control Structures
Oracle: Control Structures
 
Oracle: Dw Design
Oracle: Dw DesignOracle: Dw Design
Oracle: Dw Design
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Oracle Warehouse
Oracle WarehouseOracle Warehouse
Oracle Warehouse
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Oracle: New Plsql
Oracle: New PlsqlOracle: New Plsql
Oracle: New Plsql
 
Oracle: Fundamental Of Dw
Oracle: Fundamental Of DwOracle: Fundamental Of Dw
Oracle: Fundamental Of Dw
 

Dernier

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Dernier (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

Retrieving data and combining results in ORACLE

  • 1. 1 Using ORACLE® Retrieving data from multiple tables(joins) Sub-queries and Set operators
  • 3. 3 USES OF JOINS
  • 4. 4 EQUI JOIN Equi Join is a simple SQL join condition that uses EQUAL sign as the comparison operator Syntax: SELECT col1,col2,col3 FROM table1,table2 WHERE table1.col1=table2.col1; EQUI JOIN on product_master and customer_master tables: SELECT prod_name,prod_stock,quantity,deliver_by FROM product_master,customer_master WHERE order_id=prod_id; By this we can have an approximation of the quantity and date of products that need to be shipped out.
  • 5. 5 OUTER JOINS OUTER join condition returns all rows from both tables which satisfy the join condition along with rows which do not satisfy the join condition from one of the tables. The SQL outer join operator in Oracle is ( + ) and is used on one side of the join condition only. Syntax: SELECT col1,col2 FROM table1,table2 WHERE table1.col1 (+) = table2.col1; OUTER JOIN on product_master table and customer_master: SELECTp.prod_id, p.prod_name, o.order_id, o.quantity FROM customer_master o, product_master p WHEREp.prod_id (+)= o.order_id ;
  • 6. 6 CARTESIAN JOINS If a SQL join condition is omitted or if it is invalid the join operation will result in a Cartesian product. The Cartesian product returns a number of rows equal to the product of all rows in all the tables being joined. For example, if the first table has 20 rows and the second table has 10 rows, the result will be 20 * 10, or 200 rows. This query takes a long time to execute. SYNTAX: SELECT col1,col2 FROM table1,table2; CARTESIAN JOIN on product_master and customer_master: SELECTorder_id,prod_name FROMcustomer_master,product_master; Here each row from customer_master will be Mapped to each row of product_master.Here the This query contains 50 rows only 10 rows are Shown in the figure
  • 7. 7 SELF JOINS A Self join is the type of SQL join where we join a particular table to itself. Here it is necessary to ensure that the join statement defines an ALIAS name for both the copies of the tables to avoid column ambiguity Syntax for Table Alias: SELECTs.first_nameFROMstudent_details s; In this query alias s is defined for the table student_details and the column first_name is selected from the table. Self Join on Course table: SELECTa.course_nameASCOURSE,b.course_nameAS PREREQUSITE_COURSE FROMcourse_ma,course_m b WHEREa.pre_course=b.course_id;
  • 8. 8 NATURAL/CARTESIAN JOINS CARTESIAN JOIN is also known as NATURAL JOIN .The output of this join can be filtered using the WHERE clause. SELECTprod_ID,prod_name ,order_id,quantity FROM product_master NATURAL JOIN customer_master WHERE prod_name LIKE ('teak%') AND quantity=10;
  • 9. 9 SUBQUERY IN SQL A Subquery is also called as an Inner query or a Nested query. It is a query inside another query. A subquery is usually added in the WHERE Clause of the SQL statement. Most of the time, a subquery is used when we know how to search for a value using a SELECT statement, but do not know the exact value. Subqueries are an alternate way of returning data from multiple tables Subqueries can be used with the following sql statements along with the comparision operators like =, <, >, >=, <= etc. Usually, a subquery should return only one record, but sometimes it can also return multiple records when used with operators like IN, NOT IN in the where clause. SELECT column….. FROM tablename WHERE SUBQUERY rown …… The result set of the subquery act as the condition set for the main query row1 The SELECT subquery statement
  • 10. 10 SET OPERATORS Set operators combine the results of two component queries into a single result. Queries containing set operators are called compound queries. The Set Operators in SQL are:
  • 11. 11 SET OPERATOR - UNION The UNION set operator is used to combine multiple subqueries and their outputs. The UNION clause merges the outputs of two or more subqueries into one in such a way that the Result set = Records only in query 1 + Records only in query 2 + A single set of records common to both query 1 and query 2 . Example: SELECT * FROM InfoTable WHERE age = 40 UNION SELECT * FROM InfoTable WHERE age = 45; Result Set Records from Query 1 Records from Query 2 Query 1 Query 2 Records common to both Queries
  • 12. 12 SET OPERATOR - INTERSECT The INTERSECT set operator is used to combine multiple subqueries and their outputs. The INTERSECT clause merges the outputs of two or more subqueries into one in such a way that the Result set = A single set of records common to both query 1 and query 2 . Example: SELECT * FROM InfoTable WHERE age = 40 INTERSECT SELECT * FROM InfoTable WHERE age = 45; Result Set Records from Query 1 Records from Query 2 Query 1 Query 2 Records common to both Queries
  • 13. 13 SET OPERATOR - MINUS The MINUS set operator is used to combine multiple subqueries and their outputs. The MINUS clause filters records from Second Query and common records and displays the remaining records. Result set = Records only in query 1 – [ Records only in query 2 + A single set of records common to both query 1 and query 2 ]. Example: SELECT * FROM InfoTable WHERE age = 40 MINUS SELECT * FROM InfoTable WHERE age = 45; Result Set Records from Query 1 Records from Query 2 Query 1 Query 2 Records common to both Queries and from Query 2 not included in the result set
  • 14. THANK YOU 14 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit: www.dataminingtools.net