Get Started: SQL LEFT JOIN

In This Article, You Will Know About SQL LEFT JOIN. 

SQL LEFT JOIN – Before moving ahead, let’s know a bit about SQL INNER JOIN.

Table of Contents

SQL LEFT JOIN

The SQL LEFT keyword returns all records from the left table and matches answers from the right table. LEFT JOIN is also known as LEFT OUTER JOIN.

Syntax

				
					SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
				
			

Example Database

Table name: Data_1

S.No

Name

Class

1

Alex

5

2

Rolex

6

3

Salex

7

4

Jalex

8

5

Kalex

9

Table name: Data_2

S.No

Roll_No

Section_ID

6

451

A

7

452

B

8

453

C

9

454

D

10

455

E

Example: Use the SQL LEFT JOIN keyword to return the matching records from the table.

				
					SELECT Data_1.Name, Data_2.Roll_No
FROM Data_1
LEFT JOIN Data_2
ON Data_1.S.No = Data_2.S.No;
				
			

As a result, it returns records from the Name column and Roll_No column.

Example: Use the SQL LEFT JOIN keyword to return the matching records from the table ordered by Section_ID.

				
					SELECT Data_1.Name, Data_2.Roll_No
FROM Data_1
LEFT JOIN Data_2
ON Data_1.S.No = Data_2.S.No
ORDER BY Data_2.Section_ID;
				
			

As a result, it returns records from the Name column and Roll_No column, ordered by Section_ID. 

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

2 thoughts on “Get Started: SQL LEFT JOIN”

Leave a Comment

Stay in the loop

codingstreets