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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 9
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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 RUN button. 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
     

       

    ORACLE ARTICLES

    - Oracle's Turn to Play in the Sun
    - Implementing and Using Oracle`s Restore Poin...
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT