SELECT [ALL][TOP {integer | decimal} [PERCENT][WITH TIES]]
{*[.ALL]}
FROM [joined_table [RIGHT] JOIN joined_table ON search condition]
[FULL] [CROSS JOIN]
[(subquery) [AS] derived_tablename [(column name [..., column name])]
[WHERE search condition(s)]
[GROUP BY [column name |column position|expression][..., column name |column position|expression]]
[HAVING condition]
[QUALIFY condition]
[SAMPLE {fraction_description [..., fraction_description]} ]
{count_decription [..., count_description ]}
{ expression [ DESC ] [ expression [ ASC ] ] }
[ORDER BY {column name [ ] [..., column name [ ]]}];
{column position [ASC] [column position [DESC ] ] }
[WITH {expression1 [..., expression1]}]
[BY expression2 [ASC|DESC] [..., expression2 [ASC|DESC]]];
To find out number of employee present in each department, try the following.
SELECT Department.DeptNo, COUNT (Employee.employee)
FROM Employee, Department
WHERE Employee.DeptNo = Department.DeptNo
GROUP BY Department.DeptNo
(instead, you can simply write 1 which is the column position in the SELECT statement)
Example of a sub query in Teradata SQL. The following SQL shows the Name and the Department No of the employees working for the same department under a particular manager, whose ID is 117.
SELECT Name, DeptNo
FROM employee, Department
WHERE employee.DeptNo = Department.DeptNo
AND employee.DeptNo IN (SELECT DeptNo FROM Department WHERE MgrNo = 117);
If the table is very large and you want to see a sample of data, there are a couple of ways to achieve the same in Teradata. One is by using TOP operator and the other is using SAMPLE operator.
SELECT TOP 10 cust_name, balance
FROM Customers
ORDER BY balance DESC;
The above query would give TOP 10 rows after showing the result set in descending order.
This following query would give 10 randomly chosen rows after showing the result set in descending order. Note the position of the operator changes based on which one you use.
SELECT cust_name, balance
FROM Customers sample 10
ORDER BY balance DESC;
Our Random Articles
- Somdev Devvarman ousts Xavier Malisse 6-1, 3-6,7-6(5)
- How To Choose A Good Online Traffic School
- New Year Wishes 2010
- New Year Wishes
- How to use EXTRACT function with date and time columns
More Links




4 Comments
Material that you are providing is very easy to learn. But it is much better than this , if you ll give the full material of this at ONE LINK.
Thank you
Suresh.
That is right Suresh. This is the reason I have given all the links in one page, please visit this
http://readvitamin.com/teradata/
Hope this helps.
Hi. Can anyone tell me how to extract time from timestamp?
For Example
timestamp=’2008-03-28 14:11:04′
i want time ’14:11:04′ from timestamp through query.
Thanks in advance.
Hi Vaideesh,
If you need only time, you can probably try the following;
SELECT time;
To answer your question you should do something like this.
SELECT CAST(VaideeshTime as time(0)) from timestamp;
VaideeshTime
——–
14:11:04
Hope that helps.