Database SQL Basics (TryHackMe)

Search for a command to run...

No comments yet. Be the first to comment.
The CIA Triad is a pre-security room in TryHackMe that covers the fundamentals of cybersecurity: the CIA Triad, which is made up of building block i.e confidentiality, Integrity and Availability. In other areas its said that the CIA Triad has been mo...
Link to the challenge on TryHackMe: Modern Web Stacks Introduction During a time-boxed engagement, the first tester to identify Apache/2.4.49 in a Server: header already knows the exact CVE before the

Link to the challenge/walkthrough on TryHackMe: Broken Authentication Introduction Authentication is the process by which a web application verifies the identity of the user making a request. It typic

Link to the HealthGPT AI security CTF challenge on TryHackMe. Meet HealthGPT, a well-meaning virtual assistant used by a busy healthcare team. It helps clinicians look up procedures, draft notes, and

Link to the section of the AI Odyssey CTF on TryHackMe: Token City. It covers challenges like: ML Sec: The Loan Arranger | AI Sec + DFIR: Rogue Commit | AI Sec + Web App Sec: Sealed Substation | Agent

Link to the Privilege Escalation Challenge on TryHackMe: Linux Privilege Escalation: Automation Introduction By now, you should have an understanding of basic privilege escalation techniques and how t

Database SQL Basics is a pre-security room by TryHackMe that allows beginners to learn fundamentals of databases and the query language SQL which comes handy when learning about SQLI(SQL Injection) or other cybersecurity CTF challenges where the SQL queries come handy.
How can a café keep track of every order and still quickly answer questions about them later?

In the Computer Fundamentals module (coming soon), we have seen how computers can process information while running. But what happens when the computer is turned off? Where does the information go?
In this room, you will be helping a small business make sense of its data. As the company grows, keeping track of information using simple files becomes slow and confusing. Databases solve this problem by storing information in a structured way that is easy to search and manage.
Understand what data is and why it matters
Explain what a database is and why it is used
Understand what SQL is and what it is used for
Identify tables, rows, and columns
Write simple SQL queries to retrieve information
In a café database table, what does one row represent?

In this table, each column represents one type of information, such as a name or a price.
Each row represents a complete record, and the table contains all records.
Imagine a small café.
At first, the café owner writes each order in a paper notebook to track orders and payments.
Each order includes:
The drink name
The price
The time of the order
This works fine when the café is small. However, after many days, the notebook becomes full. Finding answers to questions like “How many coffees were sold today?” or “What was the cheapest drink sold this morning?” becomes slow and difficult.
The owner has to read through many pages and count orders manually. This is where computers and databases become useful.
Think of a database as a place where a computer stores information in an organised way.
You can think of a database as a digital notebook that never runs out of pages. Unlike a paper notebook, a database allows the computer to search, count, and sort information very quickly.
Even if the café has thousands of orders, a database can still answer questions in seconds.
Inside a database, information is stored in tables.
A table resembles a spreadsheet, where information is organised neatly into rows and columns.
Columns are the titles at the top of the table. They describe the type of information stored.
Rows go across the table. Each row contains one complete set of information.
For the café example:
Columns might be: order number, drink, price, and time
Each row is one café order
This means:
One column stores one type of information, such as prices
One row stores all the information about a single order
If the café sells ten drinks in one day, the table will contain ten rows. If one more customer places an order, one more row is added to the table.
If an order is removed, only that row disappears. The rest of the table stays the same.
SQL is a language used to ask questions of a database.
Instead of reading the table row by row, SQL lets the computer do the work for us.
For example, the café owner might ask:
“Show me all orders.”
“Show me only coffee orders.”
“Show me the cheapest drink.”
These questions are called queries.
A query does not change the data. It only displays the requested information from the table.
In the next task, you will learn how to write simple SQL queries to ask these questions yourself.
Inside databases, what is the term for the "spreadsheets" that store the information? table
In this task, you will use a safe browser-based database client. Nothing here can break. If you make a mistake, you can click Reset Data and try again.
At the top of the page, you can see the two tables and their columns:
Orders (id,drink,price,time)
Menu (drink, price)
Your goal is to practise writing queries using four core SQL parts: SELECT, FROM, WHERE, and ORDER BY.
We start with the most basic query. When we use SELECT *, the * symbol means all columns. The word FROM tells the database which table to use.
Try this query:
SELECT * FROM Orders;
Click Run Query. You should see every order currently stored in the database.

Sometimes we do not need every column. We can choose specific columns by listing them after SELECT.
Try this query:
SELECT drink, price FROM Orders;
This will display only the drink and price columns.

The WHERE keyword filters rows. It keeps only rows that match a condition.
Try filtering by drink name:
SELECT * FROM Orders WHERE drink = 'Coffee';
If the database contains coffee orders, you will now see only those rows.

Hint: If you are not sure which drink names exist, run:
SELECT * FROM Menu;
The ORDER BY keyword sorts results by a column. By default, results are sorted in ascending order (lowest to highest).
Try sorting orders by price (lowest first):
SELECT * FROM Orders ORDER BY price;

To sort in reverse order (highest to lowest), add DESC.
Try sorting orders by price (highest first):
SELECT * FROM Orders ORDER BY price DESC;

Most real queries combine parts together. Here, we filter to keep only one drink type and then sort by price.
Try this query:
SELECT * FROM Orders WHERE drink = 'Coffee' ORDER BY price DESC;

When you showed all orders, how many rows were returned?
SELECT * FROM Orders;

When you sorted orders by price from cheapest to most expensive, which drink appeared first?
SELECT * FROM Orders ORDER BY price;

When you sorted the menu by price from most expensive to cheapest, which drink appeared first?
SELECT * FROM Orders ORDER BY price DESC;

In this room, we learned how computers store information in databases and how SQL is used to ask clear questions about that information. Using a café example, we saw how tables organise orders into rows and columns, and how simple SQL commands can show, filter, sort, and add data.
Understanding what a database is
Knowing what tables, rows, and columns are
Asking simple questions using SQL
Reading results returned by a database
SELECT – choose what data to display
FROM – choose where the data comes from
WHERE – filter records based on a condition
ORDER BY – sort results
Question to think about:
What could happen if someone were allowed to change or remove café orders without permission?
Great work finishing this room. You are building solid foundations, so keep going.