您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

func_sql__function__FIRST

SQL FIRST() 语法


SELECT FIRST(column_name) FROM table_name;

注释:只有 MS Access 支持 FIRST() 函数。

SQL Server、MySQL 和 Oracle 中的 SQL FIRST() 工作区

SQL Server 语法


SELECT TOP 1 column_name FROM table_name
ORDER BY column_name ASC;

实例


SELECT TOP 1 name FROM Websites
ORDER BY id ASC;

MySQL 语法


SELECT column_name FROM table_name
ORDER BY column_name ASC
LIMIT 1;

实例


SELECT name FROM Websites
ORDER BY id ASC
LIMIT 1;

Oracle 语法


SELECT column_name FROM table_name
ORDER BY column_name ASC
WHERE ROWNUM <=1;

实例


SELECT name FROM Websites
ORDER BY id ASC
WHERE ROWNUM <=1;

演示数据库

在本教程中,我们将使用 RUNOOB 样本数据库。

下面是选自 "Websites" 表的数据:


+----+--------------+---------------------------+-------+---------+
+----+--------------+---------------------------+-------+---------+
<table>
<tr>
<th>1</th>
<th>Google</th>
<th>https://www.google.cm/</th>
<th>1</th>
<th>USA</th>
</tr>
<tr>
<td>3</td>
<td>菜鸟教程</td>
<td>http://www.runoob.com/</td>
<td>4689</td>
<td>CN</td>
</tr>
<tr>
<td>4</td>
<td>微博</td>
<td>http://weibo.com/</td>
<td>20</td>
<td>CN</td>
</tr>
<tr>
<td>5</td>
<td>Facebook</td>
<td>https://www.facebook.com/</td>
<td>3</td>
<td>USA</td>
</tr>
<tr>
<td>6</td>
<td>百度</td>
<td>https://www.baidu.com/</td>
<td>4</td>
<td>CN</td>
</tr>
<tr>
<td>7</td>
<td>stackoverflow</td>
<td>http://stackoverflow.com/</td>
<td>0</td>
<td>IND</td>
</tr>
</table>

+----+---------------+---------------------------+-------+---------+

SQL FIRST() 实例

下面的 SQL 语句选取 "Websites" 表的 "name" 列中第一个记录的值:

实例


SELECT name AS FirstSite FROM Websites LIMIT 1;

执行以上 SQL 结果如下所示:

![](https://www.runoob.com/wp-content/uploads/2013/09/limit1.jpg)

来源:https://www.runoob.com/sql/sql-func-first.html