I need to write a query that will return the last 15 rows from a 2 table join once certain criteria is met. The query is as follows:
select col1,col2,col3
from table1 a, table2 b
where b.col1=a.col1
and trunc(col3) <= (date)
and col2 in ('text values')
is there a simple way to get the last 15 rows of this query?
I am using SQL*PLUS 8.1.6 on a 7.2.3 DB, users may be using SQL*PLUS 3.3
thanks!
The term "the last 15 rows" is irrelevent without a sort order. Once you figure out your order, you can sort in decending order and pick the first 15 rows.
so I put in a sort by the date field desc, then what? rownum < 16 where clause before the order by?
Just for a hint, consider the following:
SELECT
---OUTER.C1
FROM
---(
------SELECT
---------INNER.C1,
---------ROWNUM
------------AS QUERY_ROWNUM
------FROM
---------(
---------SELECT
------------C1
---------FROM
------------TABLE1
---------ORDER BY
------------C1
---------) INNER
------WHERE
---------ROWNUM (LESS THAN) 8
---) OUTER
WHERE
---OUTER.QUERY_ROWNUM >= 4
---- quoted from former topic
Thanks
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks