View : 124

23/09/2026 11:46am

A beginner's hands typing an SQL command on a laptop keyboard, with a stat card noting that 58.6% of developers use SQL according to the 2025 Stack Overflow survey.

Write Your First SQL Query: Hands-On SELECT and WHERE for Beginners

#SQL

#learn SQL

#SELECT

#WHERE

#SQL for beginners

Starting from the question we get asked most

When beginners who are just learning to code ask our team "How do I actually get good at SQL?", the answer we used to give was "Try reading through the basic commands first." But after watching plenty of people finish reading and still freeze up when it was time to write their first query, we changed our answer.

SQL isn't a subject you memorize. It's a skill you build by typing it yourself and seeing the results. So this article won't march through every command definition. Instead it will walk you through writing your very first query, for real, on a single page, from SELECT all the way to filtering with WHERE, sorting, and trying a few problems on your own at the end. If you're brand new to programming in general, it's worth laying some groundwork first at learning to code on your own: where to start, then come back and tackle SQL here.

What is SQL (the shortest version that lets you start)

SQL stands for Structured Query Language. It's the language we use to "talk" to a database and tell it to fetch, add, change, or delete data. Put simply, if a database is a giant filing cabinet, SQL is the sentence we use to say "please hand me the folder that matches these conditions." The beauty of it is that we describe what we want, not how to go get it step by step. The database figures out how to find it.

Why is it worth learning? According to the 2025 Stack Overflow Developer Survey, SQL is the third most-used language among developers worldwide, at 58.6% of all respondents, and the three most popular databases (PostgreSQL, MySQL, SQLite) all use SQL. That means whether you head toward web, data, or any other track, the odds you'll run into SQL are very high (source: survey.stackoverflow.co/2025/technology, global data, 2025).

Here's something many people don't realize: SQL isn't new. It was born back in 1974 under the name SEQUEL at IBM (source: postgresql.org). Fifty years later it's still here, because the idea is simple and genuinely useful. The skill you're about to practice today is one that doesn't go stale easily, unlike frameworks that change every year.

Where SQL actually shows up in real work

Some people wonder why they should learn to pull data from a students table when in real life nobody sits around writing queries against toy tables. But the truth is that almost every app you use every day runs on SQL behind the scenes. When you open a social app and it pulls up your friends' latest posts, that's a SELECT with a WHERE filtering only the people you follow, sorted by ORDER BY on time. When a food-delivery app shows nearby restaurants that are open, that's multi-condition filtering exactly like what we're about to practice.

Seen this way, what we practice today isn't a toy. It's the same core that big systems actually use, just with larger tables and more complex conditions. If you understand SELECT and WHERE on a tiny table, you understand the same principle used on a table with millions of rows.

Another angle people overlook: SQL is a cross-functional skill, not just for programmers. Data analysts, marketers who want to pull their own customer lists, even business owners who want to know which products sell best all use SQL to get answers themselves without waiting on the tech team. That's what makes it so worth the time, and it's why we want you to start as early as possible.

Before you write: understand "table, row, column" first

Before you type your first command, let's paint the picture in your head for thirty seconds. The kind of database SQL uses stores data in "tables," which look exactly like the spreadsheets you already know.

  • Column is the heading for each kind of data, such as name, score, major, like a column header in a spreadsheet.

  • Row is one complete set of data, such as a single student with their full name, score, and major, like one line in a spreadsheet.

  • Value is the data in a single cell, such as the number 82 in the score cell.

Once you can see this picture, writing SQL becomes nothing more than saying "which columns, from which table, only the rows that match which condition." That's all. If you'd like to strengthen this kind of step-by-step thinking, read how to practice logic thinking for programmers alongside this.

Set up a practice space in 5 minutes (no heavy install needed)

The nice thing about learning SQL is that you don't need a real database installed on your machine to practice. The fastest way is to open an online SQL tool that runs in the browser, such as an online SQLite tool, type a command, and hit run. No sign-up, no fiddly setup, perfect for the early stage when you just want to get used to typing commands.

So everyone practices on the same data, we'll first create a sample table called students (the data below is made up, for practice only). Copy it in and run it once:

CREATE TABLE students (id INTEGER, name TEXT, score INTEGER, major TEXT);
INSERT INTO students VALUES (1,'Mint',82,'Data'),(2,'Beam',75,'Web'),(3,'Fah',91,'Data'),(4,'Nott',68,'Web'),(5,'Ploy',88,'AI');

Notice that when creating the table we declared the type of each column: INTEGER for whole numbers (like id and score) and TEXT for text (like name and major). This type business matters when writing conditions, because text values must be wrapped in quotes while numbers don't. You'll see this in action in the WHERE section.

Now we have a table that looks like a tiny spreadsheet, 5 rows and 4 columns, ready for your first query.

Alright, let's dive in.

Your first query: SELECT

The first command to know is SELECT, which means "show me the data." Type this line and run it:

SELECT * FROM students;

Read it out in plain language: "get (SELECT) every column (*) from the table (FROM) students." The result is all 5 rows we just inserted. The * means "all columns," and the ; at the end signals the command is done.

The result comes out as a table just like the original, with the headers id, name, score, major followed by 5 rows of data. Reading the result well matters just as much as writing the query, because in real work this is exactly where you check whether your query is right.

Now if we don't want every column, just the name and score, we list the column names instead of *:

SELECT name, score FROM students;

This time the result has just two columns. That's the heart of SELECT: you choose what to look at. In real work, tables often have dozens of columns, and picking only what you need keeps the result readable and the query fast.

You can rename a column header in the result with AS, for example to show score as the word "points":

SELECT name AS student, score AS points FROM students;

You don't need this when starting out, but it's handy later when preparing reports for others to read.

Filtering with WHERE

Pulling the whole table is easy, but in reality we usually want only the rows that match a condition, such as "only people scoring 80 or above." That's where WHERE comes in:

SELECT name, score FROM students WHERE score >= 80;

In plain language: "get name and score, from the students table, only rows where score is greater than or equal to 80." The result narrows down to Mint, Fah, and Ploy. Beam and Nott drop out because their scores don't reach it.

There are only a few comparison operators used often in WHERE. This set is enough to remember:

  • = equal to

  • > greater than / < less than

  • >= greater than or equal / <= less than or equal

  • <> not equal to

Try switching the condition to text, for example only people in the Data track:

SELECT name, score FROM students WHERE major = 'Data';

Notice that a text value must always be wrapped in single quotes 'Data', unlike numbers which you type directly. This is exactly why we stressed data types back when creating the table.

To combine several conditions at once, use AND (both must be true) or OR (either one is true):

SELECT name, score FROM students WHERE major = 'Data' AND score >= 85;

This returns only people in the Data track who also scored at least 85, which leaves just Fah, because Mint is in Data but scored 82 and doesn't meet the bar.

Two more helpers worth knowing are BETWEEN for a number range and LIKE for partial text search:

SELECT name, score FROM students WHERE score BETWEEN 80 AND 90;
SELECT name FROM students WHERE name LIKE 'M%';

The first line returns people scoring between 80 and 90, and the second returns names starting with the letter M (the % stands for "anything after this").

Sorting and limiting with ORDER BY and LIMIT

Once you can filter, the next very common step is sorting. Use ORDER BY followed by a column name, and add DESC if you want highest to lowest (the default is lowest to highest):

SELECT name, score FROM students ORDER BY score DESC;

The result is sorted from the highest scorer down. If you only want the "top 3," add LIMIT:

SELECT name, score FROM students ORDER BY score DESC LIMIT 3;

Just like that you can build a "ranking," which is an extremely common task in real work, like the top 10 best-selling products or the most active users.

Counting with COUNT

Sometimes we don't want to see the rows one by one, just how many there are. Use COUNT(*):

SELECT COUNT(*) FROM students WHERE major = 'Data';

This answers how many students are in the Data track (the answer is 2). There are more summary functions like averages and sums, but for now just knowing COUNT is enough. You can build on it later.

3 things beginners get wrong on the first query

When you're just starting, hitting an error is completely normal. It's not a sign you're bad at this. We've gathered the three most common ones so you won't be caught off guard.

  • Forgetting FROM or misspelling a column name. If you hit an error like "no such column," go back and check that the column name matches exactly what you wrote in CREATE TABLE. Typing scor instead of score, off by a single letter, is enough to fail.

  • Using the wrong quotes for text. Text values must use single quotes 'Data'. If you forget them, or use double quotes in some tools, you'll hit an error immediately. Numbers, on the other hand, must not be quoted.

  • Using == instead of =. In many programming languages we compare with ==, but in SQL a comparison in a WHERE condition uses a single equals sign =.

The most important tip is to read the error slowly instead of closing it right away. SQL error messages usually tell you exactly where the snag is, like which column couldn't be found. Once you get used to it, you'll fix things faster and faster. Debugging is a skill you can practice too.

Try it yourself, 3 problems

The thing that really cements SQL is writing it yourself. Try these three against the students table before peeking at the answers:

  1. Get the name and major of everyone scoring below 80.

  2. Get the names of people in the Web track, sorted from highest score to lowest.

  3. Count how many students in total scored 85 or above.

Answers (try them yourself first):

SELECT name, major FROM students WHERE score < 80;
SELECT name FROM students WHERE major = 'Web' ORDER BY score DESC;
SELECT COUNT(*) FROM students WHERE score >= 85;

If you can do all three, it means you've used SELECT, WHERE, ORDER BY, and COUNT across the full cycle of "asking questions of your data."

The commands you learned today

Keep this set handy to glance at when you forget:

  • SELECT columns FROM table; — choose which columns to view

  • WHERE condition — filter only the rows you want

  • AND / OR — combine multiple conditions

  • ORDER BY column DESC — sort

  • LIMIT n — limit the number of rows

  • COUNT(*) — count rows

Misconceptions beginners have about SQL

Before we wrap up, let's clear up a few misconceptions common among newcomers, because they often make people give up too early for no good reason.

First, many people think you need to be good at math or already know how to code before you can learn SQL. That's simply not true. SQL is designed to read like plain English. As we saw, a query asking for the names of people scoring over 80 reads almost like an ordinary sentence. People with no prior coding background can start comfortably.

Second, some fear they'll break the database if they type something wrong. But as long as you practice with SELECT on sample data in an online tool, you can mistype a hundred times and nothing gets damaged. It just shows an error, and you fix it and try again. This practice space is completely safe. No need to be afraid.

Third, many believe you must memorize a huge list of commands before you count as capable. In reality, people who are good at SQL don't remember every command. They understand the principles and look up the syntax when they need it. What's worth investing in is understanding what each command does, not rote memorization.

Before you go further: DELETE and UPDATE always need WHERE

Today we focused on "looking at" data with SELECT, which is very safe, because no matter how many times you run it wrong, nothing gets damaged. But once you move on to commands that "change" data like UPDATE or "delete" data like DELETE, there's one iron rule to burn into memory: these commands must always have a WHERE.

The reason is that if you write a delete command without WHERE, it wipes the entire table in one go. Likewise an update without WHERE changes every row at once. This is a classic mistake even professional developers have made. The safe trick is, before you delete or update, first write it as a SELECT with the same WHERE condition to see which rows it would touch. Once it matches what you intended, switch to the command that actually changes the data.

You don't need these commands yet, but keep this rule with you. It'll save you from accidentally wrecking real data at work down the road.

Next steps from here

If you ran all the queries above, you've crossed the hardest part of starting SQL: the "can't write a single line" wall. What's left is practicing until it feels natural and adding new commands one at a time, such as JOIN for linking data across multiple tables (like a students table and a table of enrolled courses) or GROUP BY for summarizing data into groups, such as the average score per major.

The most effective way to practice is to ask questions about real data around you and turn them into queries, like "who ordered the most this month" or "which product isn't selling." The more you practice with questions you actually want answered, the faster it sticks. Along the way, if you want tools to help you code more smoothly, check out tools that speed up coding for beginners, and if you're serious about working as a dev, knowing Linux helps a lot, so read why programmers should learn Linux.

Most important of all, don't stop at reading. Open an online SQL tool and type along with today's examples in full. That's the truest first step.

As for how to keep practicing without falling off, our advice is to aim for at least a few queries a day against this same dataset, gradually turning up the difficulty. Focus on SELECT and WHERE in the first week, then create a second table and practice JOIN the next week. A little consistency every day beats one marathon reading session followed by a month away, every time. Just don't leave too long a gap, and SQL will soon become a tool you reach for naturally.

FAQ: Frequently Asked Questions about This Article

A collection of questions and answers to help you better understand the content of this article.