1

Is there any pseducolumn concept in Teradata like ROWNUM in Oracle or, is there any way to get first 100 rows of a table ?

Thanks.

1 Answers1

4

There's no ROWNUM but you can use TOP:

select top 100 * from tab;
dnoeth
  • 59,503
  • 4
  • 39
  • 56
  • I don't even know what Teradata is, but I doubt something like this would return the **first** 100 rows of anything in any meaningful sense. Are you missing an ORDER BY, perhaps by a column or expression (or multiple ones) that the OP has yet to specify? –  Nov 18 '16 at 11:51
  • @mathguy the result order is non-deterministic. However, they are in fact the "first" 100 records returned by the query. Of course you can add an order by. However, there is nothing wrong with dnoeth's answer – David Cram Nov 18 '16 at 12:45
  • @DavidCram - perhaps not "wrong"; I was pointing to the failure to ask follow-up questions. If one is truly trying to help the OP, one would ask for clarification (or at least mention in the answer exactly what I had in my comment). –  Nov 18 '16 at 12:51
  • @mathguy: Oracle's `WHERE ROWNUM >= n` is equivalent to `TOP n` regardless if there's `ORDER BY` or not. If the OP needs an order he can simply add it. – dnoeth Nov 18 '16 at 14:59
  • @dnoeth - I did a quick search on Google (so perhaps I missed the point) but it does not seem to me that they are equivalent - at least not in syntax. `top n` can be selected in the same query where you have the `order by` clause. In Oracle you must use a subquery to get the same result (if there is something to order by). Anyway, that wasn't my point - my point was that if you want to help the OP, then help them as much as possible. –  Nov 18 '16 at 15:49
  • @mathguy: So `TOP` is even simpler than `ROWNUM` and if the OP asks a more detailed quetsion I'll gladkly give a more detailed answer :) – dnoeth Nov 18 '16 at 16:43