PostgreSQL Basic SELECT Statement: Select first ten records from a table
18. Write a query to select first ten records from a table.
Sample Solution:
Code:
-- Selecting the employee ID and first name from the employees table, limiting the result to the first 10 rows
SELECT employee_id, first_name
-- Selecting data from the employees table
FROM employees
-- Limiting the result set to the first 10 rows
LIMIT 10;
Explanation:
- This SQL code selects the employee ID and first name from the "employees" table.
- It limits the result set to include only the first 10 rows using the LIMIT clause.
- The result set will contain employee IDs and first names for the first 10 employees in the employees table, based on the default ordering of the table.
Sample table: employees
Output:
pg_exercises=# SELECT employee_id, first_name pg_exercises-# FROM employees LIMIT 10; employee_id | first_name -------------+------------ 100 | Steven 101 | Neena 102 | Lex 103 | Alexander 104 | Bruce 105 | David 106 | Valli 107 | Diana 108 | Nancy 109 | Daniel (10 rows)
Practice Online
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a query to check whether the first_name column of the employees table containing any number.
Next: Write a query to get a monthly salary (rounded up to 2 decimal places) of each employee.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/postgresql-exercises/basic/basic-select-statement-exercise-18.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics