12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Retrieving Data With QueriesSee Also:■<strong>Oracle</strong> Database <strong>SQL</strong> Reference for detailed information on usingORDER BY with SELECT.6.2.6 Displaying Data From Multiple TablesYou can use SELECT to display data from the multiple tables. This process is referredto as joining the tables. In a join, multiple tables share a similar column.When you retrieve data from multiple tables, you can explicitly identify which table acolumn belongs to. This is important when tables contain columns with the samename. You can use the complete table name to explicitly identify a column, such asemployees.employee_id, or a table alias. Note the use of the table aliases (d, e, andl) to explicitly identify the columns by table in the <strong>SQL</strong> statement. The alias is definedin the FROM clause of the <strong>SQL</strong> statement. A table alias is used to simply and reduce thesize of the <strong>SQL</strong> code.Example 6–6 is an example of querying data from joined tables using ANSI syntax.The first SELECT joins two tables and the second SELECT joins three tables.Example 6–6Selecting Data From Multiple Tables With the ANSI Join Syntax-- the following SELECT statements retrieve data from two tables-- that have a corresponding column (department_id)-- this join uses ANSI syntax, note the use of JOIN and ONSELECT e.employee_id, e.last_name, e.first_name, e.department_id,d.department_name FROM employees eJOIN departments d ON e.department_id = d.department_id;-- the following SELECT retrieves data from three tables-- two tables have the corresponding column department_id and-- two tables have the corresponding column location_idSELECT e.employee_id, e.last_name, e.first_name, e.department_id,d.department_name, d.location_id, l.country_id FROM employees eJOIN departments d ON e.department_id = d.department_idJOIN locations l ON d.location_id = l.location_id;In Example 6–7 the joins use the <strong>Oracle</strong>-proprietary syntax. There is no performancedifference between the ANSI and <strong>Oracle</strong> syntax.Example 6–7 Using SELECT to Display Data From Multiple Tables-- the following SELECT statements retrieve data from two tables-- that have a corresponding column (department_id)-- note that the employees table has been aliased to e and departments to dSELECT e.employee_id, e.last_name, e.first_name, e.department_id,d.department_name FROM employees e, departments dWHERE e.department_id = d.department_id;-- the following SELECT retrieves data from three tables-- two tables have the corresponding column department_id and-- two tables have the corresponding column location_idSELECT e.employee_id, e.department_id, d.department_name, d.location_id,l.country_id FROM employees e, departments d, locations lWHERE e.department_id = d.department_id AND d.location_id = l.location_id;6-6 <strong>SQL</strong> <strong>Developer</strong> Online Help

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!