Hello everyone! Welcome to the learning series of PostgreSQL.

Before reading this article, please read the previous article of this series.

Today, we will understand the datatypes loaded in our database and perform some filtering and browsing actions on the previously loaded database. Let’s go!

The datatypes present inside the sample db we've loaded into our Postgres are.

String or Character (VARCHAR)

VARCHAR can store strings of different lengths up to a maximum limit of 100 characters.

first_name
last_name
address
state
zip_code
phone
email
course_name

Date

This is represented by DATE datatype, which will store a year, month, and day.

course_date

Number

school_id       INT,
course_fees     DOUBLE PRECISION,
scholarship_amt DOUBLE PRECISION,

Now, let’s consider 3 scenarios, we want to retrieve the First and last Names, and Phones of students whose.

  1. The fee is more than 30000
  2. The fee is between 25000 – 30000
  3. The fee is exactly 22298.76 or 22345.67

For all the above requirements, we will use the first 2 as common statements.

SELECT 
    first_name, 
    last_name, 
    phone, 
    course_fees
FROM 
    students
WHERE 
    course_fees > 30000

The above statement gives us 9 rows as a result.

Statement

SELECT 
    first_name, 
    last_name,
    phone,
    course_fees
FROM 
    students
WHERE 
    course_fees BETWEEN 25000 AND 30000;

The above statement gives us 100 rows as a result.

Execute

SELECT 
    first_name, 
    last_name,
    phone,
    course_fees
FROM 
    students
WHERE 
    course_fees IN (22298.76, 22345.67)

The above statement gives us 2 rows as a result.

Log error

That's it for today. We will catch up in the next series of this blog with more queries! Happy learning!