Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Full Outer Join in SQL

Full Outer Join in SQL

? FULL OUTER JOIN in SQL

FULL OUTER JOIN returns all records when there is a match in either the left table or the right table.
It combines the results of both LEFT JOIN and RIGHT JOIN.


? Syntax:

SELECT columnsFROM table1FULL OUTER JOIN table2ON table1.common_column = table2.common_column;

? How it works:

Table1 ValueTable2 ValueResult
MatchesMatchesRow with combined columns
MatchesNo matchRow from table1, NULLs in table2 columns
No matchMatchesRow from table2, NULLs in table1 columns

? Example:

Table: Students

StudentIDName
1John
2Sarah
3Mike

Table: Exams

ExamIDStudentIDScore
101290
102485

Query:

SELECT s.StudentID, s.Name, e.ScoreFROM Students sFULL OUTER JOIN Exams e ON s.StudentID = e.StudentID;

Result:

StudentIDNameScore
1JohnNULL
2Sarah90
3MikeNULL
NULLNULL85

? Notes:

  • Supported in SQL Server, PostgreSQL, Oracle, etc.

  • MySQL does NOT support FULL OUTER JOIN directly. You can simulate it using a UNION of LEFT JOIN and RIGHT JOIN.


? Simulate FULL OUTER JOIN in MySQL:

SELECT s.StudentID, s.Name, e.ScoreFROM Students sLEFT JOIN Exams e ON s.StudentID = e.StudentIDUNIONSELECT s.StudentID, s.Name, e.ScoreFROM Students sRIGHT JOIN Exams e ON s.StudentID = e.StudentID;

If you'd like, I can help you write or optimize your FULL OUTER JOIN queries!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql