Day Three with SQL: Inserting Data, Querying Smarter, and Working with Real Datasets

Published: (January 7, 2026 at 06:10 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

Day three was all about reinforcing the basics, not rushing forward, but getting comfortable with SQL by practicing it repeatedly on real data.

I spent most of the day working through SQLZoo exercises, inserting data into PostgreSQL, and querying a realistic dataset generated with Mockaroo. This helped bridge the gap between theory and actual usage.

Inserting Data into Tables

I practiced inserting data into tables and learned a very useful PostgreSQL feature: importing SQL files directly.

Using the psql terminal, you can run SQL files with:

\i path_to_file/file_name.sql

To test this, I downloaded a 1,000‑row dataset from Mockaroo, adjusted table parameters and constraints to match the data, and imported it into my database. Seeing a large dataset populate my tables instantly made everything feel much more real.

Querying Data with SELECT (Again, but Better)

I continued practicing the now‑familiar SELECT statement, but with more structure and intention.

Sorting Results with ORDER BY

SELECT * FROM users ORDER BY first_name;

By default, sorting is ascending (ASC). To reverse the order:

SELECT * FROM users ORDER BY first_name DESC;

Getting Unique Values with DISTINCT

SELECT DISTINCT country FROM users;

Filtering with WHERE and Logical Operators

You can combine conditions using logical operators:

  • AND
  • OR

Comparison Operators

  • = (equal)
  • “ (less than, greater than)
  • =
  • <> (not equal)

These operators are useful for filtering ages, dates, and numeric values.

Limiting Results with LIMIT and OFFSET

SELECT * FROM users LIMIT 10 OFFSET 20;
  • LIMIT controls how many rows are returned.
  • OFFSET skips a specified number of rows.

Using FETCH Instead of LIMIT

PostgreSQL also supports the SQL‑standard FETCH syntax:

SELECT * FROM users FETCH FIRST 6 ROWS ONLY;

Searching with IN and BETWEEN

Using IN

SELECT * FROM users WHERE country IN ('Nigeria', 'Ghana', 'Kenya');

Using BETWEEN

SELECT * FROM users WHERE dob BETWEEN '1990-01-01' AND '2000-12-31';

Pattern Matching with LIKE and ILIKE

  • LIKE – case‑sensitive pattern matching
  • ILIKE – case‑insensitive pattern matching

Wildcards:

  • % – matches any number of characters
  • _ – matches exactly one character

These are handy for querying email patterns and other text fields.

Grouping Results with GROUP BY

SELECT
    country_of_birth,
    COUNT(country_of_birth) AS "Number of Users"
FROM users
GROUP BY country_of_birth
ORDER BY COUNT(country_of_birth);

This query shows how many users belong to each country, illustrating the power of aggregation.

Final Thoughts

Day three reinforced an important lesson: mastery comes from repetition. Working with a real dataset made every query feel purposeful, and practicing the same concepts in different ways helped solidify my understanding. SQL is starting to feel less like syntax and more like a way of thinking.

Tomorrow I’ll be learning and practicing even more.

Back to Blog

Related posts

Read more »