DEV Community

Agu O. Wisdom
Agu O. Wisdom

Posted on

PostgreSQL SELECT STATEMENT.

How to use the PostgreSQL SELECT statement.

In this short tutorial, you are going to learn how to use the Postgres SELECT statement to query the database and retrieve information from a table.

The Postgres SELECT statement is one of the most used queries in SQL, it is used to retrieve data from tables. It is part of the queries used to perform CRUD (Create, Read, Update, Delete) operations in SQL. The SELECT statement is the READ in the CRUD operations, since it is used to read or retrieve data.

Let's see an example of how to use SELECT.
The following shows an example on how to use SELECT:

SELECT list_name FROM table_name;
Enter fullscreen mode Exit fullscreen mode

Now, let's break it down:

  • First, specify a list, can be a column or list of columns from the table you want to query.

  • Ensure that the data you want to retrieve exists in the table.

  • If you are selecting multiple columns, you need to use comma , after each column name.

  • Use the asterisk * shorthand to retrieve all the columns from a table (not a good practice).

  • The FROM clause specifies the table you want to select from.

  • And finally, the table name, which is the name of the table you want to select from.

NOTE: In PostgreSQL, the semicolon at the end of the table name is not optional. If you skip the semicolon, Postgres will throw an error.

Conclusion: In this short tutorial, you have learned how to use the PostgreSQL SELECT to query a database and retrieve information from a table.

Top comments (0)