SQL Joins

3 Comments | 6167 Views | Post by: Admin | Tags: tech on the net, sql, sql joins, sql joining tables together, syntax, parameters, arguments, example


SQL joins are used to get rows from one or more than two tables.Learn how to use SQL joins with syntax, visual illustrations, and examples. SQL JOINS are used to retrieve data from multiple tables. A SQL JOIN is performed whenever two or more tables are joined in a SQL statement.


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;
            


Post Comments

if you have some suggestion, question, request on SQL Joins.

Please use the comment box to express your views.

 

Comments:

loading...