Example: Selecting the Name, Project, and Employee Hours - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

To select the name, project, and the number of hours spent by employees assigned to project OE1-0001, plus the names of employees not assigned to a project, the following query could be used:

   SELECT Name, Proj_Id, Hours
   FROM Employee,Charges 
   WHERE Employee.Empno = Charges.Empno 
   AND Proj_Id IN ('OE1-0001')
   UNION
   SELECT Name, NULL (CHAR (8)), NULL (DECIMAL (4,2)) 
   FROM Employee 
   WHERE Empno NOT IN
   (SELECT Empno 
   FROM Charges);

This query returns the following rows.

Name Project Id Hours
Aguilar J ? ?
Brandle B ? ?
Chin M ?  
Clements D ? ?
Kemper R    
Marston A ? ?
Phan A ? ?
Regan R ? ?
Russell S ? ?
Smith T    
Watson L    
Inglis C 0E1-0001 30.0
Inglis C 0E1-001 30.5
Leidner P 0E1-001 10.5
Leidner P 0E1-001 23.0
Moffit H 0E1-001 12.0
Moffit H 0E1-001 35.5

In this example, null expressions are used in columns 2 and 3 of the second SELECT statement. The null expressions are used as place markers so that both SELECT statements in the query contain the same number of expressions.