SunQuest
 
       Oracle
  Home arrow Oracle arrow Page 2 - 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 
VeriSign Whitepapers 
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 1. Single Table queries


    (Page 2 of 5 )

    Using the Employees table in the hr database in Oracle 10G XE, the single table query will be demonstrated. Queries can be designed in Oracle 10g XE by the query builder which may be accessed as shown from the Home page.

    The single table query will use the built-in Query designer which can be accessed from Home-->SQL-->Query Builder as shown in the following picture. You may choose the columns you want to return in the result as well as any filtering and ordering you want by making appropriate changes in the designer as shown. After making the changes run the query by hitting the RUNbutton. If you are developing queries that may end up in something complicated, it may be a good idea to save them and make changes to the saved queries as you go along.

    The corresponding SQL statement generated by the machine is shown in the next paragraph. The double reference to the "Employees" is because of the lack of support for setting the table alias in the GUI. However, the SQL generated by the GUI adds the table alias. Although Oracle 10G XE shows the table alias for a single table without joins, it is not usual to show the alias.

    select "EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
    "EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
    "EMPLOYEES"."LAST_NAME" as "LAST_NAME",
    "EMPLOYEES"."PHONE_NUMBER" as "PHONE_NUMBER",
    "EMPLOYEES"."SALARY" as "SALARY" 
    from "EMPLOYEES" "EMPLOYEES" where   "EMPLOYEES"."SALARY" >9000
    order by EMPLOYEES.LAST_NAME DESC
    

    The result returned by this query is shown in the next picture as you may verify for yourself. The filtering and the ordering are in accordance with your choice.

    In addition to the table alias which is implicit, you may also use the column alias, which may be used for column ordering but not in the column condition as shown in the SQL statement generated by the GUI. Note that although the GUI generated the alias for the columns in the SQL, it retained the original column names in the order by clause. Ordering is specified over multiple columns -- in this case two columns.

    select  "EMPLOYEES"."EMPLOYEE_ID" as "Emp_ID",
    "EMPLOYEES"."FIRST_NAME" as "Fname",
    "EMPLOYEES"."LAST_NAME" as "Lname", 
    "EMPLOYEES"."PHONE_NUMBER" as "Phone", "EMPLOYEES"."SALARY" as "Salary" from "EMPLOYEES" "EMPLOYEES" where "EMPLOYEES"."SALARY" >9000 order by EMPLOYEES.LAST_NAME DESC, EMPLOYEES.FIRST_NAME DESC

    The result returned by the query is shown in the next picture.

    The GUI does not substitute the column alias in the order by clause, but you may run this select statement in the SQL Command window by substituting "EMPLOYEES"."LAST_NAME by "Lname", and "EMPLOYEES" "FIRST_NAME" by "Fname" to obtain the same result.

    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 5 hosted by Hostway