1

I'm having a small issue with sorting the data returned from a query, with the aim of getting the oldest updated value in dataset so that I can update only that record. Here's what I'm doing:

WHERE ROWNUM = 1 AND TABLE1.ID != V_IGNOREID 
AND TABLE1.LASTREADTIME = (SELECT MIN(TABLE1.LASTREADTIME) FROM TABLE1)
ORDER BY TABLE1.LASTREADTIME DESC; 

It makes no difference as to whether the ORDER BY statement is included or not. If I only use the ROWNUM and equality checks, I get data, but it alternates between only two rows, which is why I'm trying to use the LASTREADTIME data (so that I can modify more than these two rows). Anybody have any thoughts on this, or any suggestions as to how I can use the MIN function effectively?

Cheers

4

1 に答える 1

1
select * from (
-- your original select without rownum and with order by
)
WHERE ROWNUM = 1

説明を編集する

order by条項は、条項の後の結果セットに適用されると思いますwhere。したがって、rownum = 1がと同じselectステートメントにあるorder by場合、それが最初に適用されorder by、順序付けされていない結果セットの最初の行となる1行のみが順序付けられます。

于 2012-09-05T10:21:16.380 に答える