Latest Release

 

How to Query Data in PostgreSQL — A Beginner’s Guide with Examples

Introduction

PostgreSQL (or Postgres) is one of the most powerful and open-source relational database systems used by developers, data analysts, and businesses worldwide.

If you’ve already created a database and inserted some records, the next logical step is learning how to query data — that means retrieving, filtering, sorting, and analyzing the information stored in your tables.

In this post, we’ll explore how to query data in PostgreSQL using simple and practical SQL commands that even beginners can master.


What Is a Query?

A query is a request you send to the database to get specific information.
You use SQL (Structured Query Language) commands to write these requests.

In PostgreSQL, the most common query command is:

SELECT
It tells the database which columns and records you want to retrieve.

Basic Query Syntax

Here’s the basic structure of a SELECT query in PostgreSQL:

SELECT column1, column2, ...
FROM table_name;
Example:
SELECT first_name, last_name
FROM employees;
✅ This retrieves the first_name and last_name columns from the employees table.

If you want to select all columns, use the asterisk *:

SELECT * FROM employees;

🔍 Filtering Data with WHERE

To get only specific records, use the WHERE clause.

Example:

SELECT * 
FROM employees
WHERE department = 'Finance';

This query returns only employees who work in the Finance department.

You can also use comparison operators like:

Operator Description Example
=         Equal to         WHERE salary = 50000
<> or !=         Not equal to         WHERE department <> 'HR'
>, <, >=, <=         Greater or less than         WHERE age > 30
LIKE         Pattern matching      WHERE name LIKE 'A%' (names starting with A)
IN         Matches a list         WHERE department IN ('HR', 'IT', 'Finance')

🎯 Sorting Results with ORDER BY

To arrange results in ascending or descending order:

SELECT name, salary
FROM employees
ORDER BY salary DESC;

DESC = descending (highest first)
ASC = ascending (lowest first, default)


🧮 Limiting the Number of Results

You can show only a specific number of rows using LIMIT.

Example:

SELECT * 
FROM employees
LIMIT 5;

This displays only the first five rows from the result set.


🧠 Combining Conditions with AND / OR

SELECT * 
FROM employees
WHERE department = 'IT' AND salary > 40000;

You can also use OR:

SELECT * 
FROM employees
WHERE department = 'IT' OR department = 'Finance';

📊 Aggregate Functions for Summary Data

PostgreSQL supports powerful functions for summarizing data:

Function Description Example
COUNT() Counts rows SELECT COUNT(*) FROM employees;
AVG() Average value SELECT AVG(salary) FROM employees;
SUM() Total value SELECT SUM(salary) FROM employees;
MAX() Highest value SELECT MAX(salary) FROM employees;
MIN() Lowest value SELECT MIN(salary) FROM employees;

You can combine them with GROUP BY for summaries by category:

SELECT department, AVG(salary)
FROM employees
GROUP BY department;

🔗 Joining Tables

In real projects, data is often split into multiple tables.
To combine related data, use JOIN.

Example (joining employees and departments):

SELECT e.name, d.department_name
FROM employees e
JOIN departments d
ON e.department_id = d.id;

Types of joins:

  • INNER JOIN – only matching records

  • LEFT JOIN – all from left + matches from right

  • RIGHT JOIN – all from right + matches from left

  • FULL JOIN – all records from both sides


🧰 Practical Example

Let’s assume we have a database with a table called students.

id name age grade city
1 Arun 15 A Kochi
2 Meera 14 B Thrissur
3 Rahul 15 A Ernakulam
4 Anju 13 C Kollam

Query example:

SELECT name, grade
FROM students
WHERE city = 'Ernakulam';

Output:

name grade
Rahul A

⚙️ Tools to Run PostgreSQL Queries

You can write and test these queries using:

  • pgAdmin (PostgreSQL’s official GUI)

  • psql command-line tool

  • DBeaver (open-source database client)

  • DataGrip (JetBrains IDE)

  • VS Code SQL extensions


🚀 Conclusion

Querying data in PostgreSQL is one of the most essential skills for working with databases.
With the right SELECT, WHERE, and JOIN commands, you can pull meaningful insights from your data easily.

Start simple, practice often, and soon you’ll be able to write complex queries confidently.

💡 Tip: Try combining filters, joins, and aggregates in a single query — that’s where PostgreSQL truly shines!












 



Moto G34 5g with-snapdragon 695 launched in India Price, specs, launch offers

Fastest 5G Processor -Snapdragon 695 5G

Fueled by the Snapdragon 695 5G octa-core processor and LPDDR4X memory, the Moto G34 5G delivers the speed required to maximize the capabilities of high-speed 5G networks. Experience exceptionally rapid mobile Internet speeds, leverage advanced video features and effortlessly handle all your tasks without any hassle.

Best 5G Performance

Experience ultra-fast 5G speeds on the Moto G34 5G thanks to 13 5G Bands with VoNR support, up to 4 Carrier Aggregation, and up to 4x4 MIMO. Never let a slow data connection hold you back, take advantage of advanced video features, and download at lightning-fast speed without worrying about battery life.

Premium Design with Vegan Leather Finish

With its Slim, sleek, and lightweight design, the Moto G34 5G stands out. For an extra touch of sophistication, there's a special edition made from vegan leather. Choose from Charcoal Black or Ice Blue with a 3D PMMA finish, or Ocean Green in premium vegan leather design to match your style.

Immersive (6.5) display with 120 Hz refresh rate

Experience uninterrupted gameplay and seamless scrolling on an expansive 16.51 cm (6.5) display with a rapid 120 Hz refresh rate. Immerse yourself in content without distractions, thanks to a notchless display design. Enjoy an edge-to-edge visual experience with an impressive screen-to-body ratio, bringing you closer to the heart of the action.

Stereo Speakers with Dolby Atmos

Immerse yourself in the amazing multidimensional stereo sound of Dolby Atmos. Discover new details in shows, movies, and music that you've never heard before. Experience deeper feelings in your favorite songs, bringing you closer to the artists you love.

50 MP Quad Pixel Camera with Image Auto Enhance

Capture stunningly sharp and vivid photos, even in low-light conditions, with the advanced 50 MP Quad Pixel camera featuring Image Auto Enhance. Zoom in to seize the smallest details using the dedicated Macro Vision camera. Additionally, showcase your brightest smile with the 16 MP selfie camera.

5000 mAh Battery with 20 W TurboPower Charger

Say goodbye to battery worries. The massive 5000 mAh battery ensures you can enjoy your playlists, and video chats with friends, and binge-watch your favorite series without any interruptions. Then fuel up fast with the speed of a 20 W TurboPower charger.

Latest Android 14 with My UX

Enjoy using Android 14, the latest version of the world’s most popular mobile operating system. With My UX, your phone works the way you want. Control it with simple gestures, customize your entertainment settings, and create a look that’s one in a million.

Additional RAM Boost - up to 16 GB RAM

RAM Boost transforms storage into temporary RAM for extra speed. Activate it, and your phone can add up to 8 GB of extra RAM to open apps faster and multitask seamlessly. The 8 GB variant will have an extra 8 GB of Virtual RAM, while the 4 GB variant will include an additional 4 GB of virtual RAM with the RAM Boost feature.

IP52 Water-repellent design

Don’t let spills or splashes get in your way with IP52 water-repellent design. Whether you’re going for a run or taking a call in the rain, a water-repellent design keeps your phone protected.

Up To 4 GB RAM + 128 GB Storage

Switch back and forth between apps effortlessly. With 4 GB of ultrafast LPDDR4X memory, your apps and information stay ready in the background so everything runs smoothly. Store everything you love and more with 128 GB Storage with UFS 2.2.

Side Finger-Print Scanner

Forget passwords – unlock your phone effortlessly with your fingerprint. The power button/fingerprint reader on the side ensures an unlocking experience that feels natural.

Price In India

Rs. 10999/-

Display Features

Display Size

16.51 cm (6.5 inch)

Resolution

1600 x 720 Pixels

Resolution Type

HD+

GPU

Adreno 619

Display Type

HD+ IPS LCD Display

Other Display Features

120Hz Refresh Rate, Brightness: 500 nits


Os & Processor Features

Operating System

Android 14

Processor Brand

Snapdragon

Processor Type

Snapdragon 695 5G

Processor Core

Octa Core

Primary Clock Speed

2.2 GHz

Operating Frequency

5G NR: n1/n3/n5/n7/n8/n20/n28/n38/n40/n41/n77/n78 (13 5G bands with VoNR|4 CA or Carrier Aggregation|4x4 MIMO), 4G LTE: B1/B2/B3/B5/B7/B8/B18/B19/B20/B26/B28/B32/B38/B40/B41/B42, 3G WCDMA: B1/B2/B5/B8/B19, 2G GSM: B2/B3/B5/B8


Memory & Storage Features

Internal Storage

128 GB

RAM

4 GB

Supported Memory Card Type

MicroSD

Memory Card Slot Type

Hybrid Slot


Camera Features

Primary Camera Available

Yes

Primary Camera

50MP + 2MP

Primary Camera Features

Dual Camera Setup: 50MP Main Camera (f/1.8 Aperture, Quad Pixel Technology for 1.28um, PDAF) + 2MP Macro Camera (f/2.4 Aperture, 1.12um Pixel Size), Features: Ultra-Res, Dual Capture, Spot Color, Night Vision, Macro Vision, Portrait, Live Filter, Panorama, AR Stickers, Pro Mode (w/ Long Exposure), Smart Composition, Auto Smile Capture, Google Lens Integration, Active Photos, Timer, High Res Digital Zoom (Up to 8X), RAW Photo Output, HDR, Burst Shot, Assistive Grid, Leveler, Watermark, Barcode Scanner, Quick Capture, Tap Anywhere to Capture

Secondary Camera Available

Yes

Secondary Camera

16MP Front Camera

Secondary Camera Features

Front Camera Setup: 16MP (f/2.4 Aperture, 1.0um/2.0um Ultra Pixel)

Flash

Single LED Flash

HD Recording

Yes

Full HD Recording

Yes

Video Recording

Yes

Video Recording Resolution

Rear Camera: Main Camera (FHD (at 30 fps)), Macro Camera (HD (at 30 fps))

Frame Rate

30 fps

Dual Camera Lens

Primary Camera


Connectivity Features

Network Type

5G, 4G, 3G, 2G

Supported Networks

5G, 4G LTE, WCDMA, GSM

Internet Connectivity

5G, 4G, 3G, Wi-Fi

3G

Yes

Micro USB Version

Type C Port (USB 2.0)

Bluetooth Support

Yes

Bluetooth Version

v5.2

Wi-Fi

Yes

Wi-Fi Version

Wi-Fi 802.11 a/b/g/n/ac (2.4 GHz | 5 GHz)

Wi-Fi Hotspot

Yes

NFC

No

USB Connectivity

Yes

Audio Jack

3.5mm

GPS Support

Yes


Multimedia Features

FM Radio

Yes

FM Radio Recording

Yes


Battery & Power Features

Battery Capacity

5000 mAh


Dimensions

Width

74.6 mm

Height

162.7 mm

Depth

8 mm

Weight

180 g


Warranty

Warranty Summary

1 Year on Handset and 6 Months on Accessories

Domestic Warranty

1 Year



 


INSERT QUERY IN POSTGRESQL

INSERT — create new rows in a table.

What is insert query?

The Insert command in the relational databases PostgreSQL, SQL Server, and Oracle's Structured Query Language (SQL) data manipulation language (DML) is often used. The insert command is used to add one or more rows with certain table column values to a database table.

How do you write an insert query?

The INSERT INTO statement has two fundamental syntaxes, which are shown below. 

INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) 
VALUES (value1, value2, value3,...valueN);

These are the names of the columns in the table that you wish to enter the data into: column1, column2, column3,...columnN. 
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);

If you are adding values to all of the table's columns, you might not need to specify the column(s) name in the SQL query. But make sure the data are arranged in the same order as the table's column order. 
CREATE TABLE Item
(  ItemId       BIGINT          PRIMARY KEY,
   ItemCode     VARCHAR(30)     NOT NULL,
   ItemName     VARCHAR(100)    NOT NULL
); 

Check created tables list in PostgreSQL database. Click here to check Postgres show tables.

Insert a single row into table item 

INSERT INTO item VALUES
(1, 'I001', 'Cabinet'); 

To insert multiple rows using the multirow VALUES syntax

INSERT INTO item (itemid, itemcode, itemname) VALUES
(2,'B6717', 'Tampopo'),
(3,'HG120', 'The Dinner Game');

 

Please visit other related articles



 

Novice techie whatsapp

To allow anyone with a WhatsApp account to join your call by clicking the link, create and send a WhatsApp call link. You can copy the link and distribute it in another means, or you can send it over WhatsApp to an individual or group. Call link calls are encrypted from end to end.

1. Toggle to the Calls tab.

2. Select Create Call Link.

3. Choose between a voice call or a video call.

4. To transmit a link using WhatsApp or another app, select Share Link or Copy Link.

No one can predict your call links because each time you make a call link, the URL is safe, unique, and has 22 character IDs. If you lose or forget the link you've made, call links are simple to generate. If you plan to reuse your link, kindly save it. On iOS and Android, call links are currently supported in the calls tab. Share the URL only with those you can trust because everyone who has it can join your call. Users who are blocked cannot access your call link.

Note :

1. Links lose their validity after 90 days if they are not used.

2. WhatsApp has the ability to revoke links for security and privacy reasons.

3. Only mobile devices are presently supported for WhatsApp call links.