PostgreSQL – SELECT

In this article we will be looking into the basic use of PostgreSQL SELECT statement to query data from the database table. For the sake of this article we will be using the sample DVD rental database, which is explained here and can be downloaded by clicking on this link.

The SELECT statement is as complex and flexible as it can get for a query statement. It can be used with various clauses which increases it’s flexibility and use cases to query data from a table.
The various clauses that can be used with the SELECT statement are listed below:

For the sake of simplicity we will be looking into the use of SELECT statement with FROM clause in our sample DVD rental database.

The syntax for using the SELECT statement is as follows:



Syntax: SELECT select_list FROM table_name;

Now, let’s evaluate the SELECT statement in more detail,

Now let us look into a few examples of using SELECT statement in our sample database:
Example 1:
Using SELECT statement to query data from one column

SELECT first_name FROM customer;

Output:

Example 2:
Using SELECT statement to query data from multiple columns

SELECT first_name, email FROM customer;

Output:

Example 3:
Using SELECT statement to query data in all columns of a table

SELECT * FROM customer;

Output:

Example 4:
Using SELECT statement with expressions

SELECT first_name || ' ' || last_name AS full_name, email FROM customer;

Output:

Article Tags :