Joins

Posted on January 15, 2008. Filed under: Database | Tags: , , , , , |

Joins allow database users to combine data from one table with data from one or more other tables (or views, or
synonyms). Tables are joined two at a time making a new table containing all possible combinations of rows from
the original two tables.

Inner joins: Chooses the join criteria using any column names that happen to match between the two tables. The
example below displays only the employees who are executives as well.
SELECT emp.firstname, exec.surname FROM employees emp, executives exec
WHERE emp.id = exec.id;

Left Outer joins: A problem with the inner join is that only rows that match between tables are returned. The
example below will show all the employees and fill the null data for the executives.
SELECT emp.firstname, exec.surname FROM employees emp left join executives exec
ON emp.id = exec.id;
On oracle
SELECT emp.firstname, exec.surname FROM employees emp, executives exec
where emp.id = exec.id(+);

Right Outer join: A problem with the inner join is that only rows that match between tables are returned. The
example below will show all the executives and fill the null data for the employees.
SELECT emp.firstname, exec.surname FROM employees emp right join executives exec
ON emp.id = exec.id;

On oracle
SELECT emp.firstname, exec.surname FROM employees emp, executives exec
WHERE emp.id(+) = exec.id;

Full outer join: To cause SQL to create both sides of the join
SELECT emp.firstname, exec.surname FROM employees emp full join executives exec
ON emp.id = exec.id;

On oracle
SELECT emp.firstname, exec.surname FROM employees emp, executives exec
WHERE emp.id = exec.id (+)

UNION
SELECT emp.firstname, exec.surname FROM employees emp, executives exec
WHERE emp.id(+) = exec.id

Make a Comment

Make a Comment: ( None so far )

blockquote and a tags work here.

    About

    Technical Blogs – Java J2EE Architecture Development Process, Design Patterns, Strategic Planning, Performance

    RSS

    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • The latest comments to all posts in RSS
    • Subscribe in Rojo

    Meta

Liked it here?
Why not try sites on the blogroll...