Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-11-2008
Member
 
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
Reply With Quote
  #2  
Old 10-11-2008
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Join in SQL"
Thread Thread Starter Forum Replies Last Post
Can?t join friends in Max Payne 3, error "Join Failed Failure: Blacklisted. G.Kahli Video Games 3 02-06-2012 12:44 PM
Join IPS department amritraj gill Education Career and Job Discussions 2 05-01-2010 03:56 PM
How to re-join all partitions on HDD tester22 Operating Systems 2 08-10-2009 11:23 PM
Equi Join vs Natural Join in SQL Demetrius Software Development 3 14-05-2009 12:55 PM
Too many rows after Join in SQL Elkanah Software Development 2 24-03-2009 02:11 PM


All times are GMT +5.5. The time now is 11:16 PM.