FULL JOIN

Returns records when we have the corresponding foreign key in the table after FULL JOIN. We have complete data from the right and left tables.

Overview of join types:

 

Structure:
SELECT column_name FROM table_name1
FULL JOIN table_name2 ON table_name1.column_name = table_name2.column_name;

 

 

Example1:

We search from two tables: Friends table, Colors table.

Table Color:

COLORID COLOR
1 blue
2 green
3 pink
4 yellow

 

Table Friends:

FRIENDID FRIEND COLORID
1 Frank 1
2 Helena 2
3 Julia -
4 Thomas 4

 

We search from two tables: Friends table, Colors table.

We search from two tables: Friends table, Colors table. We are looking for records that belong together. How do we recognise them? I know this by the COLORID field, which is located in both tables. COLORID represents a number expressing color. This means that each number has a different color. COLORID is called a „foreign key“.

SELECT Friends.Friend, Friends.ColorID, Colors.Color
FROM Friends
FULL JOIN Colors
ON Friends.ColorID = Colors.ColorID;

 

He returns all the records to us. We are interested in all records, regardless of whether a foreign key is paired.

FRIEND COLORID COLOR
Frank 1 blue
Helena 2 green
- - pink
Thomas 4 yellow
Julia - -

 

Leave a Comment

Your email address will not be published. Required fields are marked *