If the query is just too complex to limit effectively, try wrapping it inside a VIEW, then SELECT TOP 10 * FROM theView
Main Topics
Browse All TopicsI am having trouble getting the top 10 rows in Teradata.
This is been complicated by a couple things:
1. I don't have permissions to create a temporary table.
2. I am using a group by function in the query.
3. I am joining to other tables in the query.
I have tried to use sample but have had problems because of joining to other tables. Maybe, I don't have the syntax correct- I just put it right before the from clause. Also, I tried the cum function, but had problems because I am using a group by.
I have asked a question similar to this before; however, this time I have the complicated factors mentioned above.
Thank you!!!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
bear in mind I don't actually KNOW TeraData, so this is based on standard MS T-SQL Syntax:
if we represent your big complex query as "SELECT BLAH FROM BOO" (I know there must be a lot more!):
CREATE VIEW MakeItEasy AS SELECT BLAH FROM BOO
GO
then you should be able to
SELECT TOP 10 * FROM MakeItEasy
hope that TeraData is close enough to MS that this works for you!
I can't chage the permissions. Kenpem, I don't have permission to create a view.
The query is below, I replaced the propietary information with the corresponding column table/names. It's:
Select
E.Column1
Count(E.Column1) AS Column2
From
Table1 F Inner Join Table2 A ON
F.Column3= A.Column3
Inner Join Table4 E ON
A.Column5 = E.Column5
Group By
E.Column1
Where
(A.Date Between '2006-01-01' AND '2006-01-31')
Order By 2 DESC
What are u using to query Teradata?
Reason why I ask is that whatever u use may support querying a query
e.g.
SELECT TOP Column2
FROM (Select E.Column1, Count(E.Column1) AS Column2
From Table1 F Inner Join Table2 A ON F.Column3= A.Column3
Inner Join Table4 E ON A.Column5 = E.Column5
Group By E.Column1
Where (A.Date Between '2006-01-01' AND '2006-01-31'))
Order By Column2
rockiroads
A subquery would be a good idea- the only problem is that you can't join in a subquery in Teradata
wstuph,
The query is suppose to get the top 10 counts-i.e. Count(E.Column1)
Again, having a row count function would be ideal...
I pasted my query here again, since this question is getting long:
Select
E.Column1
Count(E.Column1) AS Column2
From
Table1 F Inner Join Table2 A ON
F.Column3= A.Column3
Inner Join Table4 E ON
A.Column5 = E.Column5
Group By
E.Column1
Where
(A.Date Between '2006-01-01' AND '2006-01-31')
Order By 2 DESC
this may help u, I found a forum
http://www.teradataforum.c
Im trying, honest guv. Since I dont have teradata, its a touch tricky to try help u with regards to myself testing first
Ok, Im doing a google search
http://www.google.com/sear
and from there, this link looks promising
http://www.teradata.com/t/
this is using a subquery like the one I mentioned, so perhaps u can use the example here and try?
on the outer query, use RANK
Business Accounts
Answer for Membership
by: rockiroadsPosted on 2006-06-22 at 22:30:44ID: 16966380
I dont know if its possible for you but have u tried using querying your query?