2017年11月16日 星期四

Oracle 取 Top 使用 Rownum

Oracle 沒有 Top 1 或是 Limit 語法,是使用 rownum 編號
使用方式如下,在Oracle中,rownum會比group by、order by更先執行,因此要用子查詢

select xxx from (select xxx from xxx order by xxx) where rownum<2

上面那句就是取 TOP 1