Monday 10 March 2008

Oracle and JOINS

Source: http://www.techonthenet.com/sql/joins.php

Simple INNER JOIN

SELECT suppliers.supplier_id, suppliers.supplier_name, orders.order_dateFROM suppliers, ordersWHERE suppliers.supplier_id = orders.supplier_id;

OUTER JOIN

select suppliers.supplier_id, suppliers.supplier_name, orders.order_datefrom suppliers, orderswhere suppliers.supplier_id = orders.supplier_id(+);

This SQL statement would return all rows from the suppliers table and only those rows from the orders table where the joined fields are equal.

The (+) after the orders.supplier_id field indicates that, if a supplier_id value in the suppliers table does not exist in the orders table, all fields in the orders table will display as in the result set.

No comments: