Retrieving Data from Tables
Learn about retrieving data from tables in PostgreSQL.
The SELECT query
The basic unit of data storage in PostgreSQL is tables. A table consists of a collection of rows, and each row has a set of columns containing that row’s data. To get data out of a table, we use the SELECT statement.
The most basic form of the SELECT statement looks like this:
SELECT*FROM<table_name>;
It will select all of the columns in the table_name table. The wildcard character * represents all the columns.
We can specify the columns to be selected:
SELECT<field_1>,<field_2>,...<field_n>FROM<table_name>WHERE<condition>
Here, <field_1>, <field_2>, ... represents the names of the columns we want to select and <table_name> is the name of the table from which we want to fetch data.
We can use the SELECT statement as below to retrieve data from a table, Employee, containing four columns, ...