can SQL fetch the last record in a table 
Author Message
 can SQL fetch the last record in a table

set rowcount 2
select * from ...
set rowcount 0
The statement above can fetch the first two record from  a table.
Does anybody know how to fetch the last record in a table?
Thanks

sherlin



Mon, 13 Nov 2000 03:00:00 GMT
 can SQL fetch the last record in a table

Quote:

> set rowcount 2
> select * from ...
> set rowcount 0
> The statement above can fetch the first two record from  a table.
> Does anybody know how to fetch the last record in a table?

If your table has the primary key (i.e. I mean if the order (!) of the
returned
rows in the above select corresponds to the primary key) then
SET ROWCOUNT 1
SELECT * FROM ...
 ORDER BY PrimKeyColumn DESC
SET ROWCOUNT 0

If the primary key consists of the several columns then
 ORDER BY PrimKeyColumn1 DESC, PrimKeyColumn2 DESC, ..., PrimKeyColumnN
DESC

-----
Origin: I want to ride it where I like!

To reply via e-mail, remove SpammersMustDie from my address.



Mon, 13 Nov 2000 03:00:00 GMT
 can SQL fetch the last record in a table

To retrieve physically last record in a table you may use:




for
very last record.

Grigory Kanevsky



Quote:
> set rowcount 2
> select * from ...
> set rowcount 0
> The statement above can fetch the first two record from  a table.
> Does anybody know how to fetch the last record in a table?
> Thanks

> sherlin



Mon, 13 Nov 2000 03:00:00 GMT
 can SQL fetch the last record in a table

How about:

SELECT MAX(prim_key) from table_name

-Glenn


**To retrieve physically last record in a table you may use:
**


**

**for
**very last record.
**
**Grigory Kanevsky
**


**> set rowcount 2
**> select * from ...
**> set rowcount 0
**> The statement above can fetch the first two record from  a table.
**> Does anybody know how to fetch the last record in a table?
**> Thanks
**>
**> sherlin
**>
**>
**>
**



Mon, 13 Nov 2000 03:00:00 GMT
 can SQL fetch the last record in a table

Sherlin,

What do you mean by last?  In relational databases there is no concept of
first or last.  if you wish a record with the greatest or smallest value in
a set of columns then use the appropriate where clause, nested select,
and/or ascending or descending index.

Good Luck,

--
David Upham
Nan Pao Information Systems, Inc.
Tel: 886-2-2816-5511 ext. 35
Fax: 886-2-2813-2111

Quote:

>set rowcount 2
>select * from ...
>set rowcount 0
>The statement above can fetch the first two record from  a table.
>Does anybody know how to fetch the last record in a table?
>Thanks

>sherlin



Tue, 14 Nov 2000 03:00:00 GMT
 can SQL fetch the last record in a table

I haven't read your post because i only sampled the
headers, but your subject  exposes your inexperience.

Relational database tables do not define an internal
order to rows! There is no "last row" from the point
of view of the table. (There's no defined order of the
columns either, by the way).

RDBMS technology (all of the systems) in general only guarantee to
return your rows in whatever order you request them
("order by..."). If you don't request an order, some
undefined order will result, not guaranteed to be the
same each time do the query!

This is a part of the basic definition of a relational table.
Columns are the same. Unless identified by name, columns
are not guaranteed by the RDBMS to be in any order left
to right (or however you think of columns).

And more by the way, tables are not storred in the database
row-by-row. Or column-by-column. The RDBMS's vary in how
they internally treat and store data, but none do it the way you
would think.

What they *do* do is *organize* the data into rows (and columns)
and present rowsets of the data  as requested,  exactly, by SQL.

Be good!
James Febbo

http://www.mcs.net/~sqledi



Thu, 16 Nov 2000 03:00:00 GMT
 
 [ 7 post ] 

 Relevant Pages 

1. Fetch record into a plsql table (record.column_1 into table(index_1))

2. Fetch last n records

3. last records fetched

4. Fetch Last returns incorrect record

5. Performance problem in fetching record from table containg 2 million record

6. How to write SQL select (LAST record from a table)

7. Finding the last record of a table in SQL

8. Transact-SQL vs. Oracle PL/SQL record fetch

9. Linked tables in Access not fetching enough records

10. TQuery fetches all records when updating any other table or query

11. fetch the nth record in an oracle table

12. Retrieving last record from table


 
Powered by phpBB® Forum Software