Get the App
SLTechnology News&Howtos  ›  Database  › 

Oracle gets the first piece of data

Shulou Source: shulou.com Published: 2022-06-01 10:17:39 10月04日 Update

An example of sql for fetching the first piece of data is as follows:

Http://www.360doc.com/showweb/0/0/860281883.aspx

SELECT * FROM tableName where fd_rt ='A'--and rownum=1 ORDER BY fd_date DESC

Normally, the first piece of data should be 16bf4eb91606de5e0ff61f94d0f8f20f

The result of using this sql directly with the condition after where is as follows

SELECT * FROM tableName where fd_rt ='A'

And rownum=1

ORDER BY fd_date DESC

But the query result is the second piece of data.

Zhengzhou Infertility Hospital: http://www.xbzztj.com/

The correct way to use it is:

SELECT t.* from (SELECT * FROM tableName where fd_rt ='A' ORDER BY fd_date DESC) t WHERE rownum = 1

The query result of rownum as a pseudo column is actually:

SELECT tableName. *, rownum FROM tableName where fd_rt ='A'--and rownum=1 ORDER BY fd_date DESC

SELECT t.charting Rownum from (SELECT * FROM tableName where fd_rt ='A' ORDER BY fd_date DESC) t

Tags: Data results queries infertility examples hospitals actual actually methods conditions Zhengzhou Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Technology Shulou Information NVidia OPPO Reno