SlideShare a Scribd company logo
1Using ORACLE®Retrieving data from multiple tables(joins)Sub-queries and Set operators
2JOINS
3USES OF JOINS
4EQUI JOINEqui 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.
5OUTER JOINSOUTER 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.quantityFROM customer_master o, product_master pWHEREp.prod_id (+)= o.order_id  ;
6CARTESIAN JOINSIf 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_nameFROMcustomer_master,product_master;Here  each row from customer_master will be Mapped to each row of product_master.Here theThis query contains 50 rows only 10 rows are Shown in the figure
7SELF JOINSA 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_COURSEFROMcourse_ma,course_m bWHEREa.pre_course=b.course_id;
8NATURAL/CARTESIAN  JOINSCARTESIAN 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,quantityFROM product_masterNATURAL JOIN customer_masterWHERE prod_name LIKE ('teak%') AND quantity=10;
9SUBQUERY IN SQLA 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 tablesSubqueries 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 SUBQUERYrown……			The result set of the 			subquery act as the condition set for 				the main query 												row1The SELECT subquery statement
10SET OPERATORSSet 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:
11SET OPERATOR - UNIONThe 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			UNIONSELECT * FROM InfoTable WHERE age = 45; Result SetRecords from Query 1Records from Query 2Query 1Query 2Records common to both Queries
12SET OPERATOR - INTERSECTThe 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			INTERSECTSELECT * FROM InfoTable WHERE age = 45; Result SetRecords from Query 1Records from Query 2Query 1Query 2Records common to both Queries
13SET OPERATOR - MINUSThe 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			MINUSSELECT * FROM InfoTable WHERE age = 45; Result SetRecords from Query 1Records from Query 2Query 1Query 2Records common to both Queries and from Query 2 not included in the result set
THANK YOU14THANK YOU FOR VIEWING THIS PRESENTATIONFOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,please visit:  www.dataminingtools.net

More Related Content

PPTX
Constraints
PPTX
Oracle: Joins
PPTX
Sql clauses by Manan Pasricha
PPTX
Sql joins inner join self join outer joins
PPT
Joins in SQL
PPTX
Aggregate function
PPT
SQL select clause
PPTX
Sql queries presentation
Constraints
Oracle: Joins
Sql clauses by Manan Pasricha
Sql joins inner join self join outer joins
Joins in SQL
Aggregate function
SQL select clause
Sql queries presentation

What's hot (20)

PDF
Sub query_SQL
 
PPT
Sql join
PPTX
MYSQL join
PPTX
sql function(ppt)
PPTX
SQL JOIN
PPT
Working with Databases and MySQL
PPTX
Group By, Having Clause and Order By clause
PDF
[APJ] Common Table Expressions (CTEs) in SQL
 
PDF
SQL JOINS
PPTX
Sql subquery
PPT
SQL subquery
PPT
Sql joins
PDF
SQL Queries - DML Commands
ODP
Oracle SQL Advanced
PPTX
DATABASE CONSTRAINTS
PDF
Introduction to oracle functions
PPT
Introduction to structured query language (sql)
PPTX
Recursion
Sub query_SQL
 
Sql join
MYSQL join
sql function(ppt)
SQL JOIN
Working with Databases and MySQL
Group By, Having Clause and Order By clause
[APJ] Common Table Expressions (CTEs) in SQL
 
SQL JOINS
Sql subquery
SQL subquery
Sql joins
SQL Queries - DML Commands
Oracle SQL Advanced
DATABASE CONSTRAINTS
Introduction to oracle functions
Introduction to structured query language (sql)
Recursion
Ad

Viewers also liked (20)

PPTX
WEKA: Output Knowledge Representation
PPTX
Procedures And Functions in Matlab
PPTX
XL-MINER:Prediction
PPTX
Txomin Hartz Txikia
PPTX
LISP: Declarations In Lisp
PDF
Huidige status van de testtaal TTCN-3
PPTX
Oracle: DML
PDF
Cinnamonhotel saigon 2013_01
PPTX
Data Applied:Tree Maps
PDF
Ontwikkeling In Eigen Handen Nl Web
PPTX
MySql:Basics
PPTX
Introduction To Programming in Matlab
PPTX
MS Sql Server: Doing Calculations With Functions
PPTX
R Datatypes
PPT
Excel Datamining Addin Intermediate
PPTX
DataKraft - Powerful No-Coding Platform for Business Applications
PPTX
R Statistics
PPTX
Matlab: Discrete Linear Systems
PPTX
Data Applied: Association
PPTX
Control Statements in Matlab
WEKA: Output Knowledge Representation
Procedures And Functions in Matlab
XL-MINER:Prediction
Txomin Hartz Txikia
LISP: Declarations In Lisp
Huidige status van de testtaal TTCN-3
Oracle: DML
Cinnamonhotel saigon 2013_01
Data Applied:Tree Maps
Ontwikkeling In Eigen Handen Nl Web
MySql:Basics
Introduction To Programming in Matlab
MS Sql Server: Doing Calculations With Functions
R Datatypes
Excel Datamining Addin Intermediate
DataKraft - Powerful No-Coding Platform for Business Applications
R Statistics
Matlab: Discrete Linear Systems
Data Applied: Association
Control Statements in Matlab
Ad

Similar to Oracle: Joins (20)

PDF
DBMS Nested & Sub Queries Set operations
PPTX
Subqueriesandjoins unit6
PPTX
SQL Joins & Sub Queries class number 697
PPTX
1. dml select statement reterive data
PDF
Sql joins
PPT
Ch7
PDF
How to work with Subquery in Data Mining?
PPTX
MULTIPLE TABLES
PPTX
MergeResult_2024_02_09_08_59_11.pptx
PPTX
advanced sql(database)
PPTX
OracleSQLraining.pptx
PPTX
joins and subqueries in big data analysis
PPTX
PDF
SQL JOINS
PDF
Oracle SQL Part 3
PPTX
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
PPTX
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
PPT
Displaying Data from Multiple Tables - Oracle Data Base
PDF
Sql wksht-6
DBMS Nested & Sub Queries Set operations
Subqueriesandjoins unit6
SQL Joins & Sub Queries class number 697
1. dml select statement reterive data
Sql joins
Ch7
How to work with Subquery in Data Mining?
MULTIPLE TABLES
MergeResult_2024_02_09_08_59_11.pptx
advanced sql(database)
OracleSQLraining.pptx
joins and subqueries in big data analysis
SQL JOINS
Oracle SQL Part 3
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
Displaying Data from Multiple Tables - Oracle Data Base
Sql wksht-6

More from DataminingTools Inc (20)

PPTX
Terminology Machine Learning
PPTX
Techniques Machine Learning
PPTX
Machine learning Introduction
PPTX
Areas of machine leanring
PPTX
AI: Planning and AI
PPTX
AI: Logic in AI 2
PPTX
AI: Logic in AI
PPTX
AI: Learning in AI 2
PPTX
AI: Learning in AI
PPTX
AI: Introduction to artificial intelligence
PPTX
AI: Belief Networks
PPTX
AI: AI & Searching
PPTX
AI: AI & Problem Solving
PPTX
Data Mining: Text and web mining
PPTX
Data Mining: Outlier analysis
PPTX
Data Mining: Mining stream time series and sequence data
PPTX
Data Mining: Mining ,associations, and correlations
PPTX
Data Mining: Graph mining and social network analysis
PPTX
Data warehouse and olap technology
PPTX
Data Mining: Data processing
Terminology Machine Learning
Techniques Machine Learning
Machine learning Introduction
Areas of machine leanring
AI: Planning and AI
AI: Logic in AI 2
AI: Logic in AI
AI: Learning in AI 2
AI: Learning in AI
AI: Introduction to artificial intelligence
AI: Belief Networks
AI: AI & Searching
AI: AI & Problem Solving
Data Mining: Text and web mining
Data Mining: Outlier analysis
Data Mining: Mining stream time series and sequence data
Data Mining: Mining ,associations, and correlations
Data Mining: Graph mining and social network analysis
Data warehouse and olap technology
Data Mining: Data processing

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
Machine learning based COVID-19 study performance prediction
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
NewMind AI Monthly Chronicles - July 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity

Oracle: Joins

  • 1. 1Using ORACLE®Retrieving data from multiple tables(joins)Sub-queries and Set operators
  • 4. 4EQUI JOINEqui 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. 5OUTER JOINSOUTER 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.quantityFROM customer_master o, product_master pWHEREp.prod_id (+)= o.order_id ;
  • 6. 6CARTESIAN JOINSIf 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_nameFROMcustomer_master,product_master;Here each row from customer_master will be Mapped to each row of product_master.Here theThis query contains 50 rows only 10 rows are Shown in the figure
  • 7. 7SELF JOINSA 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_COURSEFROMcourse_ma,course_m bWHEREa.pre_course=b.course_id;
  • 8. 8NATURAL/CARTESIAN JOINSCARTESIAN 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,quantityFROM product_masterNATURAL JOIN customer_masterWHERE prod_name LIKE ('teak%') AND quantity=10;
  • 9. 9SUBQUERY IN SQLA 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 tablesSubqueries 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 SUBQUERYrown…… The result set of the subquery act as the condition set for the main query row1The SELECT subquery statement
  • 10. 10SET OPERATORSSet 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. 11SET OPERATOR - UNIONThe 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 UNIONSELECT * FROM InfoTable WHERE age = 45; Result SetRecords from Query 1Records from Query 2Query 1Query 2Records common to both Queries
  • 12. 12SET OPERATOR - INTERSECTThe 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 INTERSECTSELECT * FROM InfoTable WHERE age = 45; Result SetRecords from Query 1Records from Query 2Query 1Query 2Records common to both Queries
  • 13. 13SET OPERATOR - MINUSThe 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 MINUSSELECT * FROM InfoTable WHERE age = 45; Result SetRecords from Query 1Records from Query 2Query 1Query 2Records common to both Queries and from Query 2 not included in the result set
  • 14. THANK YOU14THANK YOU FOR VIEWING THIS PRESENTATIONFOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,please visit: www.dataminingtools.net