Syntax: Here,

column names: Name of the columns whose value you want to retrieve FROM: The FROM clause defines one or more source tables for the SELECT. table_name: The name of an existing table that you want to query

PostgreSQL Select Statement in SQL Shell

Step 1) We have a table “tutorials” with 2 columns “id” and “tutorial_name”. Lets query it. Use the following query to list data in the table

NOTE: Use the command \c to connect to the database that contains the table you want to query. In our case, we are connected to database guru99. Step 2) If you want to view all the columns in a particular table, we can use the asterisk (*) wildcard character. This means it checks every possibility and, as a result, It will return every column.

It displays all the records of the tutorials table. Step 3) You can use the ORDER clause to sort data in a table based on a particular column. The ORDER clause organizes data in A to Z order.

You can sort from Z to A using “DESC” after the “ORDER BY” statement.

Step 4) The Select DISTINCT in PostgreSQL clause can be used to remove duplicate rows from the result. It keeps one row for each group of duplicates. Lets query Postgres Select Distinct id values from our table tutorials using distinct queries in PostgreSQL

Step 5) You can use the PostgreSQL order by LIMIT clause to restrict the number of records returned by the SELECT query

PostgreSQL Select Statement in PgAdmin

Step 1) In the Object Tree

Right Click on the Table Select Scripts Click on SELECT SCRIPT

Step 2) In the Panel on the right,

Edit the SELECT query if required Click the Lightning Icon Observe the Output

Cheat Sheet

Here, are the various parameters

column names: Name of the columns whose value you want to retrieve FROM: The FROM clause defines one or more source tables for the SELECT Unique Postgres. table_name: The name of an existing table that you want to query

Various clauses are: Use Keyword DESC to sort in descending order