Member-only story

Learning Postgres: Select, Order By, Limit, Offset (Part 6)

Tomas Svojanovsky
3 min readJun 24, 2024

--

When we insert data into tables or change schemas, we also want to see what we have.

Select

The easiest way to see everything is to use this query. It returns all columns from the table.

SELECT * FROM characters;

In PostgreSQL, we can use a shorter query that returns everything, including all columns from the table.

TABLE characters;

Both queries will return the results as below.

all rows + all columns

Order by

With the previous query, we will retrieve all rows, but they will be in the default order, which can be unpredictable. If we want to see how the results look, we can order the data. For example, if we want data starting from id1, we use ASC. If we want the latest id first, we use DESC.

SELECT * FROM characters
ORDER BY id ASC;

Now you can see how it’s nicely ordered from 1 to 11.

--

--

Tomas Svojanovsky
Tomas Svojanovsky

Written by Tomas Svojanovsky

I'm a full-stack developer. Programming isn't just my job but also my hobby. I like developing seamless user experiences and working on server-side complexities

No responses yet