Retrieving Data from a Table (PostgreSQL)
As a former 3D Animator with more than 12 years of experience, I have always been fascinated by the intersection of technology and creativity. That's why I recently shifted my career towards MERN stack development and software engineering, where I have been serving since 2021.
With my background in 3D animation, I bring a unique perspective to software development, combining creativity and technical expertise to build innovative and visually engaging applications. I have a passion for learning and staying up-to-date with the latest technologies and best practices, and I enjoy collaborating with cross-functional teams to solve complex problems and create seamless user experiences.
In my current role as a MERN stack developer, I have been responsible for developing and implementing web applications using MongoDB, Express, React, and Node.js. I have also gained experience in Agile development methodologies, version control with Git, and cloud-based deployment using platforms like Heroku and AWS.
I am committed to delivering high-quality work that meets the needs of both clients and end-users, and I am always seeking new challenges and opportunities to grow both personally and professionally.
At this point, we have successfully stored data inside the cities table.
Now the next step is to retrieve that data from the database.
To do this, PostgreSQL provides the SELECT statement.
The Basic SELECT Query
The simplest way to fetch data from a table is:
select * from cities;
When we run this query, PostgreSQL returns all rows from the cities table.
You should see all the cities we inserted earlier:
Tokyo
Delhi
Shanghai
Sao Paulo
What Does * Mean?

The * symbol (star) is a shortcut.
It means:
“Select all columns from the table.”
So:
select * from cities;
is the same as saying:
“Give me every column and every row from the
citiestable.”
This is very useful when:
exploring a table
checking inserted data
learning the structure of a table
Selecting Specific Columns

Instead of fetching all columns, we can choose only the columns we need.
Example: Name and Country
select name, country from cities;
This query returns:
only the
namecolumnand the
countrycolumn
All other columns are ignored.
Example: Name and Population
select name, population from cities;
Again, only the specified columns are returned.
Selecting More Than Two Columns
There is no limit to how many columns you can select.
select name, population, area from cities;
You can list as many columns as you want, as long as they exist in the table.
Changing Column Order
The order of columns in the result depends on how you write the query, not how the table was created.
For example:
select area, name, population from cities;
PostgreSQL will return:
area
name
population
Even though the table itself was defined in a different order.
Selecting the Same Column Multiple Times
You can even select the same column more than once:
select name, name, name from cities;
This will return the name column three times.
At first, this might look pointless, but it can be useful later when:
working with expressions
creating calculated columns
formatting output
Basic SELECT Syntax Recap
The general structure is:
select column1, column2, ...
from table_name;
Or, to get everything:
select * from table_name;
Summary
SELECTis used to retrieve data from a table*means all columnsYou can select specific columns
Column order in results is flexible
Columns can even be repeated
Now that we know how to fetch data, the next step is to filter it.
What’s Next?
In the next blog, we’ll learn how to:
filter rows using
WHEREretrieve only specific records from a table
Just send the next topic whenever you’re ready 👍