Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining last row in query??

Status
Not open for further replies.

aljubicic

Programmer
Nov 7, 2002
82
AU
Hi,

I have two tables (TabA & TabB) with a foreign key on TabB referencing a PK on TabA. Therefore there is a one to many relationship between the two tables. For the query below how which may produce a number of records from TabB , how can i limit it to just giving me the last record in the set if I dont know the row count to start off with??

Select B.*
from TabA A, TabB B
where ...........


In examples will help greatly

Thanks
Anthony
 

What is the purpose of joining A to B when you are not selecting ant columns from A? [ponder]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Given that the rows are not stored in any particular order, the term "last row" has no inherent meaning here - that is, the "last row" for a query one time might not be the "last row" for the next query, even if the two queries are executed within a very short time span.
With that said, and with LKBrownDBA's excellent question yet to be answered, I think the following would get you close to what you want:
Code:
SELECT b.* 
FROM TabA a, TabB b
WHERE rownum = (SELECT count(*) FROM
                  <your original query here>
               )
AND <your original WHERE clause here>;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top