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.

Types Of Sql Join in SQL

Types Of Sql Join in SQL

Sure! Here are the main types of SQL JOINs used to combine rows from two or more tables based on related columns:


1. INNER JOIN

  • Returns only the rows where there is a match in both tables.

  • Rows without matching values in either table are excluded.

SELECT columnsFROM table1INNER JOIN table2ON table1.common_column = table2.common_column;

2. LEFT JOIN (or LEFT OUTER JOIN)

  • Returns all rows from the left table and matched rows from the right table.

  • If there is no match, the result contains NULL for right table columns.

SELECT columnsFROM table1LEFT JOIN table2ON table1.common_column = table2.common_column;

3. RIGHT JOIN (or RIGHT OUTER JOIN)

  • Returns all rows from the right table and matched rows from the left table.

  • If no match, NULL values for left table columns.

SELECT columnsFROM table1RIGHT JOIN table2ON table1.common_column = table2.common_column;

4. FULL JOIN (or FULL OUTER JOIN)

  • Returns rows when there is a match in either left or right table.

  • Non-matching rows from both sides are included with NULLs for missing parts.

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

5. CROSS JOIN

  • Returns the Cartesian product of both tables.

  • Combines every row of the first table with every row of the second table.

  • No ON clause needed.

SELECT columnsFROM table1CROSS JOIN table2;

6. SELF JOIN

  • A join where a table is joined with itself.

  • Useful for hierarchical or comparative queries.

SELECT a.columns, b.columnsFROM table1 aJOIN table1 bON a.common_column = b.related_column;

Summary Table

Join TypeDescriptionResult Includes
INNER JOINRows with matching keys in both tablesOnly matched rows
LEFT JOINAll rows from left table + matched right rowsLeft rows + NULL for non-matching right rows
RIGHT JOINAll rows from right table + matched left rowsRight rows + NULL for non-matching left rows
FULL JOINRows matched in either tableAll rows from both tables with NULLs for unmatched parts
CROSS JOINCartesian product of both tablesEvery combination of rows
SELF JOINTable joined with itselfRows combined within same table

If you want, I can provide example queries for any join type!

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