PostgreSQL – SELECT Statement
The SELECT
statement is a fundamental SQL statement used in PostgreSQL (and other relational database systems) to retrieve data from a database table. It allows you to query and retrieve specific columns and rows of data based on your criteria.
The basic syntax of a SELECT
statement in PostgreSQL is as follows:
SELECT column1, column2, ... FROM table_name WHERE condition;
Here’s a breakdown of the components:
SELECT
: The keyword indicating that you want to retrieve data.column1, column2, ...
: The columns you want to retrieve data from.FROM table_name
: The table from which you want to retrieve data.WHERE condition
: An optional condition that filters the rows based on specified criteria.
For example, let’s say you have a table named employees
with columns employee_id
, first_name
, last_name
, and salary
. You might write a SELECT
statement to retrieve the first and last names of employees whose salary is above a certain threshold:
SELECT first_name, last_name FROM employees WHERE salary > 50000;