SQL Joins

Category > SQL || Published on : Friday, October 18, 2019 || Views: 9839 || tech on the net sql sql joins sql joining tables together syntax parameters arguments example


SQL Joins

SQL joins are used to get rows from one or more than two tables.

Different SQL JOINs are:-

  1. INNER JOIN: Returns all rows when there is at least one match in BOTH tables
  2. LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
  3. RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table
  4. FULL JOIN: Return all rows when there is a match in ONE of the tables

SQL INNER JOIN

The INNER JOIN is used to selects all rows from both tables as long as there is a match between the columns in both tables.

SQL INNER JOIN Syntax

         
            SELECT column-name(s)
            FROM table-one
            INNER JOIN table-two
            ON table-one.column-name=table-two.column-name;
            

or:

            SELECT column-name(s)
            FROM table-one
            JOIN table-two
            ON table-one.column-name=table-two.column-name;
            

SQL LEFT JOIN

The LEFT JOIN used to returns all rows from the left table (table-one), with the matching rows in the right table (table-two). The result is NULL in the right side when there is no match.

SQL INNER JOIN Syntax

            SELECT column-name(s)
            FROM table-one
            LEFT JOIN table-two
            ON table-one.column-name=table-two.column-name;
            

or:

            SELECT column-name(s)
            FROM table-one
            LEFT OUTER JOIN table-two
            ON table-one.column-name=table-two.column-name;
            

SQL RIGHT JOIN

The RIGHT JOIN keyword used to get all rows from the right table (table-two), with the matching rows in the left table (table-one). The result is NULL in the left side when there is no match.

SQL RIGHT JOIN Syntax

            SELECT column-name(s)
            FROM table-one
            RIGHT JOIN table-two
            ON table-one.column-name=table-two.column-name;
            

or:

            SELECT column-name(s)
            FROM table-one
            RIGHT OUTER JOIN table-two
            ON table-one.column-name=table-two.column-name;
            

SQL FULL OUTER JOIN

The FULL OUTER JOIN keyword used to get all rows from the left table (table-one) and from the right table (table-two).

The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.

SQL FULL OUTER JOIN Syntax

            SELECT column-name(s)
            FROM table-one
            FULL OUTER JOIN table-two
            ON table-one.column-name=table-two.column-name;