Lab JOINS
Lab JOINS
data,
UNION, INTERSECT and MINUS
clause
Aliases
Aliases are used to give temporary names to the columns in a table.
The AS Clause allows users to specify an alias name for items in
a SELECT statement.
The alias name will be returned as the column heading in the query
result instead of the actual column name.
Syntax: SELECT <column_name> AS <aliase_name> FROM
<table_name>
Example: SELECT ename AS "Employee Name", Dep_id AS
"Department ID" FROM employee;
Joins
Sometimes it is necessary to work with multiple tables.
Joins are used to combine records or manipulate data from two
or more tables in a database.
Tables are joined on columns that have the same data type and
data width in the tables.
Tables in a database can be related to each other with keys.
The purpose is to bind data together, across tables, without
repeating all of the data in every table.
The JOIN operator specifies how to relate tables in the query.
Joins
Consider the following two tables
Now, let us join these two tables in our SELECT statement:
SELECT ID, NAME, AGE, AMOUNT FROM CUSTOMERS, ORDERS WHERE
CUSTOMERS.ID = ORDERS.CUSTOMER_ID;
CUSTOMERS ORDERS