WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL FIRST() Function


FIRST () function

The FIRST () function returns the value of the first record in the specified column.

SQL FIRST () syntax

SELECT FIRST (column_name) FROM table_name;

Note: Only MS Access supports the FIRST () function.


SQL FIRST () workspace in SQL Server, MySQL, and Oracle

SQL Server syntax

SELECT TOP 1 column_name FROM table_name
ORDER BY column_name ASC;

Example

SELECT TOP 1 name FROM Websites
ORDER BY id ASC;

MySQL syntax

SELECT column_name FROM table_name
ORDER BY column_name ASC
LIMIT 1;

Example

SELECT name FROM Websites
ORDER BY id ASC
LIMIT 1;

Oracle syntax

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

Examples

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


Demo database

In this tutorial, we will use the welookups sample database.

Here is the data from the "Websites" table:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/| 1     | USA     |
| 2  | Indiatimes          | https://www.Indiatimes.com/| 13    | IN      |
| 3  | zomato      | http://www.zomato.com/| 4689  | IN      |
| 4  | indiamart          | http://indiamart.com/   | 20    | IN      |
| 5  | Facebook     | https://www.facebook.com/| 3     | USA     |
|  6 | Yahoo         | https://www.Yahoo.com/|     4 | IN      |
|  7 | stackoverflow | http://stackoverflow.com/|     0 | IND     |
+----+---------------+---------------------------+-------+---------+


SQL FIRST () instance

The following SQL statement selects the value of the first record in the "name" column of the "Websites" table:

Example

SELECT name AS FirstSite FROM Websites LIMIT 1;

The results of executing the above SQL are as follows:




Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.

welookups.com