Contents
SQL FIRST: Main Tips
- This function brings back the primary value of a column.
- Only MS Access database system supports this function.
Syntax of SQL FIRST
SELECT FIRST(col_name) FROM tbl_name;
Demo Database
In the below table there is a piece of "Customer" table:
ID | Name | Contact | Address | City | Postal_Code | Country |
---|---|---|---|---|---|---|
1 | Ben Choplinks | Ben Choplink | Obeesre Str. 51 | Rome | 11207 | Italy |
2 | Donald Rich | Donald Richario | Avda. de la Confgfstitución 4122 | Tallin | 17021 | Estonia |
3 | Lilly Smilkins | Lilly Smilkin | Matadsderos 2312 | Eguero | 14023 | Mexico |
4 | Brandinina | Tom Hitchins | 110 Hanegover Sq. | London | WB2 2DP | UK |
5 | Carizmos | Christiano Kerrys | Berguvsesvägen 9 | Luleå | S-968 43 | Sweden |
In the code example below we use SQL SELECT FIRST
function to pick the primary value in the "Customer" table of the "Name" column:
Example
SELECT FIRST(Name) AS FirstCustomer FROM Customers;
SQL FIRST Workaround in SQL Server, MySQL and Oracle
SQL Server: Syntax
SELECT TOP 1 col_name FROM tbl_name
ORDER BY col_name ASC;
Example
SELECT TOP 1 Name FROM Customers
ORDER BY ID ASC;
Syntax of MySQL
SELECT col_name FROM tbl_name
ORDER BY col_name ASC
LIMIT 1;
Oracle: Syntax
SELECT col_name FROM tbl_name
WHERE ROWNUM <=1
ORDER BY col_name ASC;
Example
SELECT Name FROM Customers
WHERE ROWNUM <=1
ORDER BY ID ASC;