Monday, September 1, 2008

RDBMS

Inner Join

Definition: An inner join is a join that selects only those records from both database tables that have matching values. Records with values in the joined field that do not appear in both of the database tables will be excluded from the query. One or more fields can serve as the join fields.

  • The inner join is also known as an equi-join.

Conceptual diagram of the inner join

The above shows a conceptual diagram of the inner join between Customer data and Order data.

Analogy: Consider a business that employs both managers and engineers - and some employees that are both. An inner join is like a union of this set; it selects the set of people that are both managers and engineers and provides information about them in both roles.

Outer Join

Definition: An outer join selects all of the records from one database table and only those records in the second table that have matching values in the joined field. In a left outer join, the selected records will include all of the records in the first database table. In a right outer join, the selected records will include all records of the second database table. One or more fields can serve as the join fields.

Left Outer Join example:

Conceptual diagram details the Left Outer Join

The above conceptual diagram details the Left Outer Join between Customer data and Order data

Analogy: Consider again the business that employs both managers and engineers. A left outer join selects all of the managers, providing the information about them, but in the case of managers who are also engineers, it provides additional information about them.

Right Outer Join example:

Conceptual diagram of a Right Outer Join

The above shows a conceptual diagram of a Right Outer Join between the Customer data and the Order data.

Analogy: Consider again the business that employs both managers and engineers. A right outer join selects the set of all engineers, providing information about them, but in the case of engineers and also managers, if provides additional information about them.

(Src: www.databasedev.co.uk/query_joins.html)

Joins in Venn Diagrams

JOIN OPERATOR

The JOIN operator specifies how to relate tables in the query. The JOIN operator is one of the set operations available in relational databases.

The following join types of join are available in most relational databases:

INNER OUTER (LEFT. RIGHT, FULL) CROSS

Joins may be represented as Venn diagrams, as shown below along with other common set operations:

join types

Result of applying these joins in a query:

INNER JOIN: Select only those rows that have values in common in the columns specified in the ON clause.

LEFT, RIGHT, or FULL OUTER JOIN: Select all rows from the table on the left (or right, or both) regardless of whether the other table has values in common and (usually) enter NULL where data is missing. (Note: FULL OUTER JOIN not implemented in Access.)

CROSS JOIN (not illustrated - not exactly a set operation): Select all possible combinations of rows and columns from both tables (Cartesian product). Not available in Access but can "happen" by not specifying relationships between tables or not setting up the appropriate joins in a query. (Not A Good Thing - the query may run for a very long time and produce a huge, not very useful result set.)

Access uses the ANSI (American National Standards Institute) style, with the JOIN and ON keywords. Access, MySQL, and Oracle all use similar syntax, with more join types and options and other set operations in MySQL and Oracle (CROSS JOIN, FULL OUTER JOIN, INTERSECT, MINUS).

src: www.udel.edu/.../SQL-Class2/SQLclass2_Join.html

No comments:

About Me

This Vamsi,Indian. When i was child, i use to think to become Detective, i dont know why, now iam Techie , future may be Farmer. I feel always Competition drives me.. Loves Challenging Jobs. Free Time Plays Cricket or Play Games in Computer. I like Characteristics of BagathSingh(Commitment),Chanakya(Strategist),Hitler(Manager,Initiater) . My Principle is follow the moto of the Rule , Not Rule. Newtons Formula applies to me :"Every object in a state of uniform motion tends to remain in that state of motion unless an external force is applied to it" , in other Words a bit Lazy.