关于取第一条数据的sql特此作了一个例子如下:

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

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

正常说 第一条数据应为  16bf4eb91606de5e0ff61f94d0f8f20f


在where 后 直接跟条件 使用此sql时结果如下 


SELECT * FROM tableName where fd_rt = 'A' 

and rownum=1 

ORDER BY fd_date DESC 


20190730115221457.png

可是查询结果为 第二条数据

 

郑州不孕不育医院:http://www.xbzztj.com/

正确使用方式为:

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

rownum作为伪列实际上查询结果为:

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

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