EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Oracle Tutorial Oracle Cross Join
Secondary Sidebar
Oracle Tutorial
  • Joins
    • Joins in Oracle
    • Inner Join in Oracle
    • Oracle Cross Join
    • Left Join in Oracle
    • OUTER Join in Oracle
    • Oracle Full Outer Join
    • Natural Join in Oracle
    • Oracle Self Join
    • Oracle hash join
    • Oracle? Update with Join
  • Basic
    • Oracle Marketing Cloud
    • What is Oracle?
    • Career in Oracle
    • How to Install Oracle
    • Oracle Versions
    • What Is Oracle Database
    • Oracle Data Warehousing
    • Oracle Warehouse Builder
    • Career In Oracle Database Administrator
    • Career In Oracle DBA
    • What is Oracle RAC
    • Oracle DBA
    • Oracle? Vanderbilt
    • What is RMAN Oracle
    • Oracle Database Administration
    • Oracle Operators
    • Oracle Constraints
    • Oracle number
    • Oracle Data Types
    • Oracle UNIQUE Constraint
    • Oracle Check Constraint
  • Oracle SET Operators
    • UNION in Oracle
    • Oracle UNION ALL
    • INTERSECT in Oracle
    • MINUS in Oracle
  • Advanced
    • Timestamp to Date in Oracle
    • Oracle Golden Gate
    • Oracle Virtual Machine
    • Oracle Describe Table
    • Oracle Clauses
    • Oracle Having Clause
    • Oracle?Primavera
    • Oracle FOREIGN Key
    • PIVOT in Oracle
    • Oracle Alter Table
    • Oracle Queries
    • Oracle Views
    • Oracle Window Functions
    • Oracle String Functions
    • Oracle Date Functions
    • Oracle Analytic Functions
    • Oracle Aggregate Functions
    • Select in Oracle
    • INSERT in Oracle
    • DISTINCT in Oracle
    • Function in Oracle
    • Oracle GROUP_CONCAT
    • Oracle INSTR()
    • Oracle CONVERT
    • Oracle LENGTH()
    • Oracle EXISTS
    • Oracle REPLACE()
    • Oracle MERGE
    • Oracle LEAD()
    • Oracle EXTRACT()
    • Oracle LISTAGG()
    • Oracle SYS_CONTEXT()
    • Oracle COALESCE
    • Oracle NVL()
    • Oracle SYSDATE()
    • Oracle?Date Format
    • Oracle SYS_GUID()
    • Oracle WILDCARDS
    • Oracle Synonyms
    • Oracle Subquery
    • BETWEEN in Oracle
    • FETCH in Oracle
    • Oracle Index
    • Oracle Function-based Index
    • Oracle UNIQUE Index
    • Oracle Bitmap Index
    • Oracle Column
    • Oracle Triggers
    • Oracle Procedures
    • Sample Database for Oracle
    • Oracle LIKE Operator
    • ORDER BY in Oracle
    • Oracle ORDER BY DESC
    • GROUP BY in Oracle
    • Oracle GROUP BY HAVING
    • Oracle Aliases
    • Table in Oracle
    • Oracle Temporary Table
    • Oracle? Table Partition
    • Oracle rename table
    • Oracle CTE
    • Cursor in Oracle
    • Oracle LOCK TABLE
    • Oracle Tablespace
    • Oracle CARDINALITY
    • Oracle REGEXP
    • Oracle REGEXP_REPLACE
    • Oracle to_date
    • JSON in Oracle
    • Oracle COMMIT
    • Oracle GRANT
    • Oracle MD5
    • Oracle ROLLBACK
    • Oracle Users
    • Oracle TIMESTAMP
    • IF THEN ELSE in Oracle
    • Oracle While Loop
    • Oracle Clone Database
    • Oracle Backup Database
    • Oracle? XML
    • Oracle XMLAGG
    • Oracle XMLTABLE
    • Oracle Performance Tuning
    • Oracle B Tree Index
    • Oracle fusion
    • Oracle ebs
    • Oracle GRC
    • Oracle ERP
    • Oracle ASM
    • Oracle Cloud
    • Oracle HCM Cloud
    • Oracle Integration Cloud
    • Oracle Jinitiator
    • Oracle pathfinder
    • Oracle VirtualBox
    • Oracle Weblogic Server
    • Oracle decode
    • Oracle Exadata
    • Oracle ZFS
    • Oracle? utilities
    • JDBC Driver for Oracle
    • Oracle? DBA Versions
    • Oracle DBA Salary
  • Interview Questions
    • Oracle Interview Questions
    • Oracle Apps Interview Questions
    • Oracle Apps Technical Interview Questions
    • Oracle Database Interview Questions
    • Oracle Forms Interview Questions
    • Oracle PL/SQL Interview Questions
    • Oracle RAC Interview Questions
    • Oracle SOA Interview Questions

Related Courses

Oracle Course Training

Oracle DBA Certification Course

MongoDB Certification Training

Oracle Cross Join

By Priya PedamkarPriya Pedamkar

oracle-cross-join

Introduction to Oracle Cross Join

A Cross Join is also called as Cartesian Product, as it is a type of Join function that returns a result set by joining every row item of one table with each and every item of the other table. If table A is cross joined with another table B, where table A has 10 records and table B has 10 records, the result set will have 100 records. Cross Join in Oracle can have a WHERE condition optionally.

Syntax:

SELECT *
FROM table1
CROSS JOIN table2
[where condition];

Parameters:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

  • table1: Here we provide the name of the first table
  • table2: Here we provide the name of the second table
  • [where condition]: It is optional and it means that whatever records that satisfy the condition will be extracted.

As we can see the syntax is very simple and easy to understand. Next in this article, we are going to discuss the working of cross join.

How Cross Join Works in Oracle?

A cross join is a cross product of two tables or it is also called a Cartesian product. We need to understand the term Cartesian in this respect. So, a Cartesian product means that every row of one table is joined to all the rows of the other table. This results in a Cartesian product, suppose we have two tables with three and four rows respectively. So if we do cross join between those two tables we will have 4*3 =12 rows. So to generalize if we have two tables with x rows and y rows then the Cartesian product will be x*y and the same is for cross join and the number of rows that will be extracted from the two tables is equal to the Cartesian product between the two tables which is x*y in this case. One important point to note that things may change if we have where condition in the query because then the actual number of rows returned will also depend on whether where the condition is satisfied or not.

This explains to us the working of the cross join in oracle. Now we will look into various examples to understand better.

Examples to Implement Cross Join in Oracle

So now we are going to look at different examples to better understand oracle cross join. So, we will be working with two tables’ employee tables with six columns 12 rows and a vehicle table with four columns 9 rows.

Example #1 – Cross Join without Condition

In this example, we are going to try to find the simple Cartesian product or cross join between two tables stored in the database. The tables are employee and vehicle. As discussed the employee table has 12 rows and the vehicle table has 9 rows. So when we discussed earlier the working of cross join, we discussed that there is no join condition provided in this type of join which we get when we do outer or inner joins. The query for this can be written in two ways both of which provide us with the same output. Below both, the queries are written

Query:

SELECT * FROM employee, vehicle;
SELECT * FROM employee CROSS JOIN vehicle;

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,650 ratings)

Both queries represent the same data. So, in this case, we are selecting all the records which we are extracting from the database. AS we have already discussed that cross join is a Cartesian product of two tables. The employee table has 12 rows and 6 columns whereas the vehicle table has 9 rows and 4 columns. As per Cartesian rule, it should be 12*9 =108 rows and 10 columns because every row of the employee will join with every other row of the vehicle.

The queries when running on Oracle SQL developer displays the below output.

Output:

Oracle Cross Join-1.1

If you see the above screenshot it shows 108 rows as well as all columns from the two tables.

Example #2 – Cross Join with Specific Columns but No Conditions

In this example it is similar to the earlier example we saw the only difference is that here only specific columns between two tables are to be extracted the working operation of the query remains the same as the earlier query. The query for the same is written below:

Query:

SELECT employee.employee_id, employee.name,
vehicle.vehicle_id, employee.VEHICLE_NAME
FROM employee CROSS JOIN vehicle;

If you see the query we have taken two columns from each table. Now let us execute the query in sql developer and the output screenshot is below.

Oracle Cross Join-1.2

As we can see the number of rows is the Cartesian product of the two tables explained earlier. Only the number of columns is four as we had mentioned the same in our query.

Example #3 – Cross Join with WHERE Condition

So, in this example, we will use the WHERE condition in our query. When we apply the WHERE clause with the condition the records which after the Cartesian product of the two tables satisfy the condition of the WHERE clause will be extracted. We will be using the same two tables used for earlier examples. The query for the operation is provided below.

Query:

SELECT employee.employee_id,  employee.name,
vehicle.vehicle_id,  vehicle.VEHICLE_NAME
FROM employee CROSS JOIN vehicle
WHERE vehicle.VEHICLE_NAME='Honda';

Now if we see at the end of the query it has a condition which states that only those records which have value as ‘Honda’ in the vehicle_name column of the vehicle table will be extracted as output.

Let us run the above query in the Oracle SQL database and the output of the same is shown below as screenshot.

Output:

WHERE Condition

If we see the output closely we can see that we only have ‘Honda’ as values in the vehicle_name column for all records. The number of rows count is also 24 which mean that there were only twenty-four records who has vehicle name as ‘Honda’.

Recommended Articles

This is a guide to the Oracle Cross Join. Here we discuss how to implement Cross Join using different conditions in Oracle along with examples. You may also look at the following articles to learn more –

  1. Types of Join in Spark SQL
  2. Top 6 Types of Joins in MySQL
  3. 10 Different Types of Joins in Oracle
  4. A Quick Glance of Different Oracle Versions
Popular Course in this category
Oracle Training (14 Courses, 8+ Projects)
  14 Online Courses |  8 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle DBA Database Management System Training (2 Courses)4.9
All in One Financial Analyst Bundle- 250+ Courses, 40+ Projects4.8
1 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more