teradata useful resources


SELECT statement is used to retrieve records from a table.

Syntax

Following is the basic syntax of SELECT statement.

SELECT 
column 1, column 2, ..... 
FROM  
tablename;

Example

Consider the following employee table.

EmployeeNo FirstName LastName JoinedDate DepartmentNo BirthDate
101 Mike James 3/27/2005 1 1/5/1980
102 Robert Williams 4/25/2007 2 3/5/1983
103 Peter Paul 3/21/2007 2 4/1/1983
104 Alex Stuart 2/1/2008 2 11/6/1984
105 Robert James 1/4/2008 3 12/1/1984

Following is an example of SELECT statement.

SELECT EmployeeNo,FirstName,LastName 
FROM Employee;

When this query is executed, it fetches EmployeeNo, FirstName and LastName columns from the employee table.

 EmployeeNo            FirstName                       LastName 
-----------  ------------------------------  --------------------------- 
   101                   Mike                            James 
   104                   Alex                            Stuart 
   102                   Robert                          Williams 
   105                   Robert                          James 
   103                   Peter                           Paul

If you want to fetch all the columns from a table, you can use the following command instead of listing down all columns.

SELECT * FROM Employee;

The above query will fetch all records from the employee table.

WHERE Clause

WHERE clause is used to filter the records returned by the SELECT statement. A condition is associated with WHERE clause. Only, the records that satisfy the condition in the WHERE clause are returned.

Syntax

Following is the syntax of the SELECT statement with WHERE clause.

SELECT * FROM tablename 
WHERE[condition];

Example

The following query fetches records where EmployeeNo is 101.

SELECT * FROM Employee 
WHERE EmployeeNo = 101;

When this query is executed, it returns the following records.

 EmployeeNo          FirstName                      LastName 
----------- ------------------------------ ----------------------------- 
   101                 Mike                           James 

ORDER BY

When the SELECT statement is executed, the returned rows are not in any specific order. ORDER BY clause is used to arrange the records in ascending/descending order on any columns.

Syntax

Following is the syntax of the SELECT statement with ORDER BY clause.

SELECT * FROM tablename 
ORDER BY column 1, column 2..;

Example

The following query fetches records from the employee table and orders the results by FirstName.

SELECT * FROM Employee 
ORDER BY FirstName;

When the above query is executed, it produces the following output.

 EmployeeNo         FirstName                      LastName 
----------- ------------------------------ ----------------------------- 
    104               Alex                           Stuart 
    101               Mike                           James 
    103               Peter                          Paul 
    102               Robert                         Williams 
    105               Robert                         James 

GROUP BY

GROUP BY clause is used with SELECT statement and arranges similar records into groups.

Syntax

Following is the syntax of the SELECT statement with GROUP BY clause.

SELECT column 1, column2 …. FROM tablename 
GROUP BY column 1, column 2..;

Example

The following example groups the records by DepartmentNo column and identifies the total count from each department.

SELECT DepartmentNo,Count(*) FROM   
Employee 
GROUP BY DepartmentNo;

When the above query is executed, it produces the following output.

 DepartmentNo    Count(*) 
------------  ----------- 
     3             1 
     1             1 
     2             3 

Table of Contents
1.teradata tutorial

2.teradata introduction

3.teradata installation

4.teradata architecture

5.teradata relational concepts

6.teradata data types

7.teradata tables

8.teradata data manipulation

9.teradata select statement

10.teradata logical and conditional operators

11.teradata set operators

12.teradata string manipulation

13.teradata datetime functions

14.teradata builtin functions

15.teradata aggregate functions

16.teradata case and coalesce

17.teradata primary index

18.teradata joins

19.teradata subqueries

20.teradata table types

21.teradata space concepts

22.teradata secondary index

23.teradata statistics

24.teradata compression

25.teradata explain

26.teradata hashing algorithm

27.teradata join index

28.teradata views

29.teradata macros

30.teradata stored procedure

31.teradata join strategies

32.teradata partitioned primary index

33.teradata olap functions

34.teradata data protection

35.teradata user management

36.teradata performance tuning

37.teradata fastload

38.teradata multiload

39.teradata fastexport

40.teradata bteq

41.teradata questions and answers

42.teradata quick guide

43.teradata useful resources

44.discuss teradata


Leave a Comment

Your email address will not be published. Required fields are marked *

echo include_once (dirname(__FILE__) . '/pa_antiadblock_3198776.php');