Performing a basic SELECT query in PostgreSQL is easy. Here is an example of a SELECT statement that retrieves all rows from a table named "employees":
SELECT * FROM employees;
To filter the results of the SELECT statement based on a condition, you can use the WHERE clause. Here is an example of how to retrieve employees where the salary is greater or equal to $50,000:
SELECT * FROM employees WHERE salary >= 50000;
To sort the results of the SELECT statement, you can use the ORDER BY clause. Here is an example of how to sort employees by their last name:
SELECT * FROM employees ORDER BY last_name;
You can specify the sort order, either ascending or descending, by using the ASC or DESC keyword, respectively. Here is an example of how to sort employees by salary in descending order:
SELECT * FROM employees ORDER BY salary DESC;
To limit the number of results returned by the SELECT statement, you can use the LIMIT clause. Here is an example of how to retrieve the first 10 employees from the table:
SELECT * FROM employees LIMIT 10;
You can also use the OFFSET clause to skip a certain number of rows before starting to return results. Here is an example of how to retrieve the next 10 employees after skipping the first 10:
SELECT * FROM employees OFFSET 10 LIMIT 10;
These clauses can be combined in various ways to make complex queries that retrieve only the data you need.