ODBC and JDBC Guide

Table Of Contents
Chapter 7
|
Supported standards 37
FROM clause
The FROM clause indicates the tables that are used in the SELECT statement. The format is:
FROM table_name [table_alias] [, table_name [table_alias]]
table_name is the name of a table in the current database.
table_alias can be used to give the table a more descriptive name, to abbreviate a longer table name, or
to include the same table in the query more than once (for example, in self-joins).
Field names can be prefixed with the table name or the table alias. For example, given the table specification
FROM employee E, you can refer to the LAST_NAME field as E.LAST_NAME. Table aliases must be
used if the SELECT statement joins a table to itself. For example:
SELECT * FROM employee E, employee F WHERE E.manager_id = F.employee_id
The equal sign (=) includes only matching rows in the results.
If you are joining more than one table, and you want to discard all rows that don’t have corresponding rows
in both source tables, you can use INNER JOIN. For example:
SELECT *
FROM Salespeople INNER JOIN Sales_Data
ON Salespeople.Salesperson_ID = Sales_Data.Salesperson_ID
If you are joining two tables, but you don’t want to discard rows of the first table (the “left” table), you can
use LEFT JOIN.
SELECT *
FROM Salespeople LEFT JOIN Sales Data
ON Salespeople.Salesperson ID = Sales Data.DepartmentID
Every row from the “Salespeople” table will appear in the joined table.
If you are joining two tables, but you don’t want to discard rows of the second table (the “right” table), you
can use RIGHT JOIN.
SELECT *
FROM Salespeople RIGHT JOIN Sales Data
ON Salespeople.Salesperson ID = Sales Data.DepartmentID
Every row from the “Sales Data” table will appear in the joined table.
Notes
1 LEFT JOIN is supported, but the grammar LEFT OUTER JOIN is not currently supported.
1 RIGHT JOIN is supported, but the grammar RIGHT OUTER JOIN is not currently supported.
1 FULL OUTER JOIN is not currently supported.
WHERE clause
The WHERE clause specifies the conditions that records must meet to be retrieved. The WHERE clause
contains conditions in the form:
WHERE expr1 rel_operator expr2
expr1 and expr2 can be field names, constant values, or expressions.
rel_operator is the relational operator that links the two expressions. For example, the following
SELECT statement retrieves the names of employees who make $20,000 or more.
SELECT last_name,first_name FROM emp WHERE salary >= 20000