The Wayback Machine - https://web.archive.org/web/20240708020214/https://www.geeksforgeeks.org/implicit-join-vs-explicit-join-in-sql/
Open In App

Implicit Join vs Explicit Join in SQL

Last Updated : 28 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

JOIN clause is used to combine rows from two or more tables, based on a relation between them. There are two different syntax forms to perform JOIN operation:

  • Explicit join
  • Implicit join

Step 1: Creating the Database

Use the below SQL statement to create a database called geeks:

CREATE DATABASE geeks;

Step 2: Using the Database

Use the below SQL statement to switch the database context to geeks:

USE geeks;

Step 3: Creating the Tables

Use the below SQL statement to create a table called student:

CREATE TABLE student(
  ROLL_NO INT PRIMARY KEY,
  NAME VARCHAR(25),
  AGE INT);

Use the below SQL statement to create a table called course:

CREATE TABLE course(
  COURSE_ID INT,
  ROLL_NO INT);

Step 4: Adding Data to the Tables

Use the below SQL statement to add the data to the student table:

INSERT INTO student 
VALUES 
(1, 'Anjali', 20), 
(2, 'Rachna', 18), 
(3, 'Shubham', 21), 
(4, 'Harsh', 25), 
(5, 'Shivam', 18), 
(6, 'Harshit', 20);

Use the below SQL statement to add the data to the course table:

INSERT INTO course 
VALUES 
(1, 1),
(2, 2),
(2, 3),
(5, 4),
(3, 5);

Step 5: Student Table

Use the below SQL statement to view the content of the student table:

SELECT * FROM student;

Course Table:

Use the below SQL statement to view the content of the course table:

SELECT * FROM course;

Step 6: Explicit Join 

This notation uses the ON keyword to specify the predicates for Join and the JOIN keyword to specify the tables to join. Join can be of any type i.e. INNER JOIN, LEFT JOIN, RIGHT JOIN, or FULL JOIN. It is easier to understand and less prone to errors.

Syntax:

SELECT column_names
FROM table1
JOIN table2
ON table1.column_name = table2.column_name

The following query will show the course id, names, and age of students enrolled in different courses by using explicit join notation.

Query:

SELECT COURSE_ID, NAME, AGE 
FROM student
JOIN course
ON student.ROLL_NO = course.ROLL_NO;

Output:

Step 7: Implicit Join 

This notation simply lists the tables for joining (in the FROM clause of the SELECT statement), using commas to separate them and WHERE clause to apply to join predicates. It performs a CROSS JOIN. It is difficult to understand and more prone to errors.

Syntax:

SELECT column_names
FROM table1, table2
WHERE table1.column_name = table2.column_name

The following query will show the course id, names, and age of students enrolled in different courses by using implicit join notation.

Query:

SELECT COURSE_ID, NAME, AGE 
FROM student, course
WHERE student.ROLL_NO = course.ROLL_NO;

Output:



Similar Reads

SQL | Join (Cartesian Join & Self Join)
SQL| JOIN(Inner, Left, Right and Full Joins) In this article, we will discuss about the remaining two JOINS: CARTESIAN JOIN SELF JOIN Consider the two tables below: StudentCourse CARTESIAN JOIN: The CARTESIAN JOIN is also known as CROSS JOIN. In a CARTESIAN JOIN there is a join for each row of one table to every row of another table. This usually h
2 min read
How to fix Cannot Insert Explicit Value For Identity Column in Table in SQL
In SQL, the error message "Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF" is a common issue encountered when attempting to insert explicit values into an identity column in a table. This error occurs because SQL, by default, does not allow explicit values to be inserted into identity columns un
7 min read
SQL Full Outer Join Using Left and Right Outer Join and Union Clause
An SQL join statement is used to combine rows or information from two or more than two tables on the basis of a common attribute or field. There are basically four types of JOINS in SQL. In this article, we will discuss FULL OUTER JOIN using LEFT OUTER Join, RIGHT OUTER JOIN, and UNION clause. Consider the two tables below: Sample Input Table 1: Pu
3 min read
Difference between Inner Join and Outer Join in SQL
1. Inner Join : It is a type of join operation in SQL. Inner join is an operation that returns combined tuples between two or more tables where at least one attribute is in common. If there is no attribute in common between tables then it will return nothing. Syntax: select * from table1 INNER JOIN table2 on table1.column_name = table2.column_name;
2 min read
Difference between Natural join and Inner Join in SQL
The join operation merges the two tables based on the same attribute name and their datatypes are known as Natural join Unlike INNER JOIN, which requires you to specify the columns and conditions for the join explicitly. In this article, we will also see the differences between them. Let's start with Natural Join. Example: If you have two tables "S
3 min read
Left join and Right join in MS SQL Server
Prerequisite – Introduction of MS SQL Server 1. Left Join : A join combines the set of two tables only. A left join is used when a user wants to extract the left table's data only. Left join not only combines the left table's rows but also the rows that match alongside the right table. Syntax - select select_list from table1 left join table2 on joi
2 min read
Self Join and Cross Join in MS SQL Server
Prerequisite - Introduction of MS SQL Server 1. Self Join : Self-join allows us to join a table itself. It is useful when a user wants to compare the data (rows) within the same table. Syntax - select select_list from T t1 [Inner|Left] Join on T t2 on join_predicate. Here T refers to the table we use for comparison and it is referred twice. To avoi
2 min read
SQL | EQUI Join and NON EQUI JOIN
Types of SQL Joins are explained in left, right, and full join and SQL | Join (Cartesian Join & Self Join). And Remaining EQUI Join and NON-EQUI will discuss in this article. Let's discuss one by one. SQL JOINS : EQUI JoinNON-EQUI Join Example - Let's Consider the two tables given below. Table name — Student In this table, you have I'd, name, c
2 min read
SQL Left Outer Join vs Left Join
In SQL, both "LEFT JOIN" and "LEFT OUTER JOIN" are used to combine data from two or more tables based on a related column, but they are essentially the same operation, and there is no practical difference between them. The keyword "OUTER" is optional in most database systems, including popular ones like MySQL, PostgreSQL, and SQL Server. Left JoinA
4 min read
Full join and Inner join in MS SQL Server
Prerequisite - Introduction of MS SQL Server1. Full Join : Full join selects all the rows from left and the right tables along with the matching rows as well. If there are no matching rows, it will be displayed as NULL. Syntax - select select_list from table1 full join table2 on join _predicate (OR) select * from table1 full join table2 2. Inner Jo
2 min read
Article Tags :