SQLforGeeks
  • Home
  • SQL
  • SQL Tutorial
  • SQL Syntax
  • Our Services
Contact
  1. SQL
  2. SQL Joins

Text copied!

« Previous
Next »

SQL Joins

Dec. 25, 2022, 6:56 p.m. under SQL

  • Hi! You should check SQL constraints post first.

    SQL join is a technique used to combine two or more tables data by using a common column or key. It allows you to retrieve data from multiple tables based on a relationship between them.

    The syntax for a SQL join typically looks like this :
    SELECT column_name(s)
    FROM table1
    JOIN table2
    ON table1.column_name = table2.column_name;
    There are several types of SQL joins, including :
    INNER JOIN :

    INNER JOIN(or JOIN) returns only the matching rows between two tables. By default 'JOIN' keyword is treated as 'INNER JOIN'. Syntax :

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

    LEFT JOIN (or LEFT OUTER JOIN) returns all the rows from the left table and the matching rows from the right table. If there is no match, the result will have null values for the right table columns. Syntax :

    SELECT column_name(s)
    FROM table1
    LEFT JOIN table2
    ON table1.column_name = table2.column_name;
            
    SQL Joins
    RIGHT JOIN :

    RIGHT JOIN (or RIGHT OUTER JOIN) returns all the rows from the right table and the matching rows from the left table. If there is no match, the result will have null values for the left table columns. Syntax :

    SELECT column_name(s)
    FROM table1
    RIGHT JOIN table2
    ON table1.column_name = table2.column_name;
            
    SQL Joins
    FULL JOIN :

    FULL JOIN (or FULL OUTER JOIN) returns all the rows from both tables, with null values for the columns that do not have a match in the other table. Syntax :

    SELECT column_name(s)
    FROM table1
    FULL JOIN table2
    ON table1.column_name = table2.column_name;
            
    SQL Joins
    CROSS JOIN :

    CROSS JOIN combines each row from one table with every row from another table. Typically, it is used to generate all possible combinations of rows from two or more tables. Syntax :

    SELECT column_name(s)
    FROM table1
    CROSS JOIN table2;
            
    SQL Joins
    SELF JOIN :

    SELF JOIN is the type of join, where a table is joined with itself as if it were two separate tables. It is useful where a table contains hierarchical data or when comparing data within the same table. Syntax :

    SELECT column_name(s)
    FROM table1 t1
    JOIN table1 t2 ON t1.column_name = t2.column_name;
            

    OR

    SELECT column_name(s)
    FROM table1 t1, table1 t2
    WHERE condition;
            
    SQL Joins
    To enhance your understanding of 'SQL joins', be sure to check out our next tutorial.

    Frequently Asked Questions :

    What are the 4 types of joins in SQL?

    The four types of joins in SQL are: INNER JOIN, LEFT JOIN (or LEFT OUTER JOIN), RIGHT JOIN (or RIGHT OUTER JOIN), and FULL JOIN (or FULL OUTER JOIN).

    What is joining in SQL?

    Joining in SQL is the process of combining rows from two or more tables based on a related column between them.

    How to add 3 joins in SQL?

    To add three joins in SQL, you would specify the JOIN condition for each additional table you want to join with, typically in the FROM clause of your SQL query.

    What is a full join?

    A full join in SQL returns all rows from both tables being joined, combining rows where there is a match and including unmatched rows from both tables.
    Thank You! You should check SQL inner join post next.
    « Previous
    Next »
    RELATED :

    What is SQL

    What is T-SQL

    Difference between DBMS and Data Warehouse

    Download SQL Server

    Install SQL Server

    Download SQL Server Management Studio SSMS

    SQL Server Management Studio

    SQL Database

    Download database

    Restore database

    Backup database

    Attach database

    Detach database

    Create database

    Delete database

    Rename database

    Select database

    Database offline

    Database online

    SQL Commands

    SQL Tables

    Create table

    Truncate table

    Delete table

    Rename table

    Select table

    Alter table

    SQL Data Types

    SQL Comments

    SQL Constraints

    SQL inner join

    SQL left join

    SQL right join

    SQL full join

    SQL cross join

    SQL self join

    INSERT INTO SELECT statement

    INSERT INTO statement

    SQL Clauses

    SELECT clause

    FROM clause

    WHERE clause

    GROUP BY clause

    HAVING clause

    ORDER BY clause

    JOIN clause

    UNION clause

    UNION ALL clause

    TOP clause

    DISTINCT clause

    SQL Operators

    SQL Arithmetic operators

    SQL Comparison operators

    SQL Logical operators

    UNION operator

    UNION ALL operator

    INTERSECT operator

    EXCEPT operator

    LIKE operator

    NOT LIKE operator

    IN operator

    NOT IN operator

    IS NULL operator

    IS NOT NULL operator

    EXISTS operator

    NOT EXISTS operator

    BETWEEN operator

    NOT BETWEEN operator

    SQL Functions

    SQL Built-In functions

    CHARINDEX function

    DATEADD function

    CONCAT function

    LEN function

    REPLACE function

    SUBSTRING function

    CASE statement

    GETDATE function

    DATEPART function

    DATEDIFF function

    CAST function

    TRY_CAST function

    CONVERT function

    TRY_CONVERT function

    ISNULL function

    NULLIF function

    COALESCE function

    SQL Window functions

    ROW_NUMBER function

    RANK function

    DENSE_RANK function

    IIF function

    CHOOSE function

    SQL Store Procedure

    Store Procedure vs. Function

    SQL Subquery

    SQL Aliases

    Temp table

    SQL Error Handling

    SQL Variables

    SQL Views

    SQL Merge

    SQL CTE

    SQL WITH TIES

    Define Transaction in DBMS

    ACID properties in DBMS

    Types of Triggers in DBMS


    • Have Some Questions?
    logo

    Elevate your data experience with SQL excellence

    Quick Links
    •  Home
    •  SQL Tutorial
    •  SQL Syntax
    •  Our Services
    Our Services
    • Web Development
    • BI Development
    • Data Warehousing
    • Data Integration ETL


    Follow Us

    GST Registered: XXAXXXXXXXZX
    Mumbai, Maharashtra, India support@sqlforgeeks.com

    © 2025 Copyright™ | All Rights Reserved | Privacy Policy