Oracle
  Home arrow Oracle arrow Page 3 - Multi-Table Queries with Oracle 10G XE
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ORACLE

Multi-Table Queries with Oracle 10G XE
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 8
    2006-11-29

    Table of Contents:
  • Multi-Table Queries with Oracle 10G XE
  • Example 1. Single Table queries
  • Example 2. Two Tables: Join Employees and Departments tables
  • Example 3. Three tables: Employees, Departments, and Locations
  • Example 4. Four tables: Employees, Departments, Locations and Countries

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Multi-Table Queries with Oracle 10G XE - Example 2. Two Tables: Join Employees and Departments tables


    (Page 3 of 5 )

    If you review the Employees table and the Departments table you will observe that the column common to both of them is the DEPARTMENT_ID. It is the primary key of the Departments table and the foreign key of the Employees table. This means that many employees may belong to the same department. Since two tables are involved, the FROM clause lists both tables, showing their aliases as well. The relationship in the query builder is as shown in the next picture. In the GUI the connecting line may not actually show the two DEPARTMENT_IDs as being joined, but you may place the mouse on the connecting line which shows the join condition.

    The query which is configured in the query Builder is shown in the next paragraph as a machine generated SQL select statement. It also has the additional where clause for filtering employees with salary > 4800. This is an example of a Complex join. A Simple join, also known as an inner join, returns just the rows for which the equality of the join condition is satisfied.

    select  "EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
    "EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
    "EMPLOYEES"."LAST_NAME" as "LAST_NAME",
    "EMPLOYEES"."EMAIL" as "EMAIL",
    "EMPLOYEES"."PHONE_NUMBER" as "PHONE_NUMBER",
    "EMPLOYEES"."HIRE_DATE" as "HIRE_DATE",
    "EMPLOYEES"."SALARY" as "SALARY",
    "DEPARTMENTS"."DEPARTMENT_NAME" as "DEPARTMENT_NAME",
    "DEPARTMENTS"."MANAGER_ID" as "MANAGER_ID" 
    from  "DEPARTMENTS" "DEPARTMENTS",
    "EMPLOYEES" "EMPLOYEES" 
    where   "EMPLOYEES"."DEPARTMENT_ID"="DEPARTMENTS"."DEPARTMENT_ID"
    and   "EMPLOYEES"."SALARY" > 4800
    

    Also as described in the earlier tutorials you may create the left outer and the right outer joins. Depending on the data in the tables you may get different number of rows returned by the queries. For example with the left outer join you get 57 rows, but for the right outer join you will get 58 rows. To understand the outer joins the Venn diagrams are very useful. This is especially true if a greater  number of tables are involved in the join. We will consider the various kinds of possible joins including the 'Full Outer' join when we return to this topic using the ANSI syntax.

    More Oracle Articles
    More By Jayaram Krishnaswamy


       · This is a continuation of the usage of the query builder tool in Oracle 10g XE....
     

       

    ORACLE ARTICLES

    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...
    - Sub-templates and More with Oracle HTML DB
    - Focusing on Templates in Oracle HTML DB





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway