Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Introduction to the Teradata® RDBMS for UNIX® Version 2 Release 2.1 - NCR

NCR Introduction to the Teradata® RDBMS for UNIX® Version 2 Release 2.1 - NCR, 1998. - 315 p.
Download (direct link): inntroduktionteradata1998.pdf
Previous << 1 .. 28 29 30 31 32 33 < 34 > 35 36 37 38 39 40 .. 76 >> Next


5-7
Data Manipulation

Using Fully Qualified Names to Reference Databases and Tables in Teradata SQL

Introduction

Fully Qualified Names

Using Fully Qualified Names to Reference Databases and Tables in Teradata SQL

Successful query operations in a Teradata database require unique names for each element of the query object: the database, the table, and the column (or columns) queried. Because several tables within a given database might have columns with the same name, it is necessary to develop a mechanism for ensuring uniqueness. This mechanism is the fully qualified name.

A fully qualified name in a Teradata base consists of the database name, the table name, and the column name concatenated together.

This is done using the following format:

databasename.tablename.columnname

Such a column reference is considered to be a fully qualified name.

For example, to fully qualify column JobTitle in table Employee in database Personnel, you would type

Personnel.Employee.JobTitle

You do not need to specify a fully qualified name if the reference is otherwise unambiguous. You need not specify a database name (or table name) if they occur elsewhere in the statement and no ambiguity results from the omission.

5-8

Introduction to the Teradata RDBMS for UNIX
Data Manipulation

Simple SQL Queries: Using the SELECT Statement

Introduction

Selecting All Rows from a Table

Selecting Specific Columns from a Table

Simple SQL Queries: Using the SELECT Statement

This topic describes simple SQL queries of a Teradata database using the SELECT statement.

The most simple Teradata SQL query is one that selects all rows from a table.

If the table is named Employee, the query looks like this:

SELECT *

FROM Employee ;

Note that the asterisk character denotes all columns.

The PROJECT operator of the relational algebra permits you to select data from individual columns using the SELECT statement.

For example, to select only the names, salaries, and positions of employees, the query looks like this:

SELECT Name,

Salary,

JobTitle FROM Employee ;

This query produces the following results table. Note there is no ordering to the rows. Columns are ordered by their precedence in the SELECT statement. Facilities for ordering rows in the results table are described later in this topic.

Introduction to the Teradata RDBMS for UNIX

5-9
Data Manipulation

Simple SQL Queries: Using the SELECT Statement

Selecting Specific Rows from a Table

Name Salary JobTitle
Peterson J 25,000.00 Payroll Ck
Moffit H 35,000.00 Recruiter
Leidner P 23,000.00 Secretary
Smith T 42,000.00 Engineer
Omura H 40,000.00 Programmer
Kemper R 29,000.00 Assembler
Aguilan J 45,000.00 Manager
Phan A 55,000.00 Vice Pres
Marston A 22,000.00 Secretary
Reed C 30,000.00 Technician
Chin M 38,000.00 Controller
Watson L 56,000.00 Vice Pres
Regan R 44,000.00 Purchaser

The SELECT operator of the relational algebra permits you to select data from individual rows using the SELECT statement.

For example, to report the name, salary, and job title for only employees in department 100, the query looks like this:

SELECT Name,

Salary,

JobTitle FROM Employee WHERE DeptNo = 10 0 ;

This query produces the following results table.

Name Salary JobTitle
Peterson J 25,000.00 Payroll Ck
Moffit H 35,000.00 Recruiter
Chin M 38,000.00 Controller

5-10

Introduction to the Teradata RDBMS for UNIX
Data Manipulation

Simple SQL Queries: Using the SELECT Statement

Using Comparison and Logical Operators to Select Specific Rows

You can use various comparison and logical operators with the WHERE clause in a Teradata SQL statement to further refine your selection of rows from a table.

You can use any column name and specify any compound selection criteria.

For example, suppose you wanted to report the names and salaries of employees in departments 100 and 600 who earn more than $35,000.00 per year. The query looks like this:

SELECT Name,

Salary FROM Employee WHERE DeptNo IN (10 0, 600)

AND

Salary > 35000

;

In this query, the IN set operator is used in the WHERE clause in place of the = comparison operator to specify the condition:

WHERE DeptNo = 100 OR

DeptNo = 600

The first part of the WHERE clause in the query could have been written in this form to produce the same result.

This query produces the following results table.

Name Salary
Aguilan J 45,000.00
Chin M 38,000.00
Regan R 44,000.00

Introduction to the Teradata RDBMS for UNIX

5-11
Data Manipulation

Simple SQL Queries: Using the SELECT Statement

Specifying Order in the Results Table

Defining Groups

The ORDER BY clause determines the sequence of returned data in the results table.

Suppose you wanted to report the name and years of experience for each employee in department 600 and you wanted to list them in ascending order of seniority. The query looks like this:
Previous << 1 .. 28 29 30 31 32 33 < 34 > 35 36 37 38 39 40 .. 76 >> Next