Results 1 to 2 of 2

Thread: Join in SQL

  1. #1
    Join Date
    Jun 2008
    Posts
    144

    Join in SQL

    SQL specifies four types of JOIN: INNER, OUTER, LEFT, and RIGHT. The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.

    A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.

    JOIN: Return rows when there is at least one match in both tables

    Inner join

    An inner join requires each record in the two joined tables to have a matching record. An inner join essentially combines the records from two tables (A and B) based on a given join-predicate.

    SELECT column_name(s)
    FROM table_name1
    INNER JOIN table_name2
    ON table_name1.column_name=table_name2.column_name

  2. #2
    Join Date
    Jun 2008
    Posts
    144

    Re: Join in SQL

    The OUTER JOIN clause differs from the standard JOIN clause (also known as the INNER JOIN clause) in that rows are returned even when there are no matches through the JOIN critieria on the second table.

    Use the SQL OUTER JOIN whenever multiple tables must be accessed through a SQL SELECT statement and results should be returned if there is not a match between the JOINed tables.

    Right Outer Join

    A Right Outer Join will take two tables and join them together based on the linking field.
    A Right Outer Join will include ALL entries from the table on the RIGHT.

    Syntax

    SELECT * FROM table_name1 OUTER table_name2
    ON table_name1.column_name = table_name2.column_name

    Example

    Code:
    SELECT *FROM   employee RIGHT OUTER JOIN department 
              ON employee.DepartmentID = department.DepartmentID
    Left Outer Join

    A Left Outer Join will take two tables and join them together based on the linking field
    A Left Outer Join will include ALL entries from the table on the LEFT

    Syntax

    SELECT * FROM table_name1 LEFT OUTER JOIN table_name2
    ON table_name1.column_name = table_name2.column_name

    Example

    Code:
     SELECT * FROM   employee  LEFT OUTER JOIN department  
    ON employee.DepartmentID = department.DepartmentID

Similar Threads

  1. Replies: 3
    Last Post: 02-06-2012, 12:44 PM
  2. Join IPS department
    By amritraj gill in forum Education Career and Job Discussions
    Replies: 2
    Last Post: 05-01-2010, 03:56 PM
  3. How to re-join all partitions on HDD
    By tester22 in forum Operating Systems
    Replies: 2
    Last Post: 08-10-2009, 11:23 PM
  4. Equi Join vs Natural Join in SQL
    By Demetrius in forum Software Development
    Replies: 3
    Last Post: 14-05-2009, 12:55 PM
  5. Too many rows after Join in SQL
    By Elkanah in forum Software Development
    Replies: 2
    Last Post: 24-03-2009, 02:11 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,160,387.82999 seconds with 16 queries