在项目中用到了查询符合条件的第一条记录,在此特地整理了一下供需要的朋友分享:
查询数据库前几条记录:
oracle:
前一条 select * from table where rownum=1 [table取自己表的名字]
前n条 select * from table where rownum<=n order by id [n是取得记录条数,table取自己表的名字]
ms sql:
前n条 select top n from table [table取自己表的名字]
mysql:
前n条 select field from table where limit n [n是取得记录条数,table取自己表的名字]
如果要查询数据库后几条记录,很简单,只要order by id(排序条件) desc 倒序排列就可以了!