如何取出查询结果的第一条记录
select
u.userid,u.name,u.cardid,u.ukeyid,s.fwtime
from user_infotbl u
join sys_userfwjltbl s
on u.userid=s.userid
where cardid='640122197007042110'
order by s.fwtime desc;
查询出一个结果集,我想只要第一条记录,怎么写sql
------解决方案--------------------select * from (
select
u.userid,u.name,u.cardid,u.ukeyid,s.fwtime
from user_infotbl u ,
sys_userfwjltbl s
where u.userid=s.userid
and cardid='640122197007042110'
order by s.fwtime desc) where rownum <2;
------解决方案--------------------在外层加个rownum=1或rownum<2,表示取第一条记录
SQL code
select *
from (select u.userid, u.name, u.cardid, u.ukeyid, s.fwtime
from user_infotbl u
join sys_userfwjltbl s on u.userid = s.userid
where cardid = '640122197007042110'
order by s.fwtime desc)
where rownum = 1;
------解决方案--------------------
如果是分组取每组第一 可以用row_number() over()函数 如果只是单独取一条 上面可以实现