Welcome to your first lesson on Basic Queries! Have you ever wondered how schools keep records of students, their examination scores, names, ages, and school fees? Or how banks find a customer's account information within seconds?
They use something called a database. A database helps people store and organise information. But how do we find information inside a database? We use something called a query.
In this module, you will learn what databases and queries are, how they work, and why they are important in our everyday lives.
Imagine your school has 2,000 students. Each student has a name, age, class, admission number, and examination results.
Now imagine your teacher wants to find the examination score of a student named Tunde. Searching through 2,000 paper files could take a very long time.
But if the school uses a computer database, the teacher can request the information using a command. This request is called a database query.
A database query is simply a question or instruction given to a database to find, display, or work with information.
Example:
Imagine asking a school database:
Each of these requests is an example of a database query.
A database is an organised collection of information stored electronically. Think of it as a digital filing cabinet where information can be stored and found easily.
Inside a database, information is often arranged in tables. A table looks similar to an Excel spreadsheet, with rows and columns.
Example: A School Students Table
| Student ID | Name | Age | Class |
|---|---|---|---|
| 101 | Tunde | 13 | JSS 2 |
| 102 | Amaka | 12 | JSS 1 |
| 103 | David | 14 | JSS 3 |
| 104 | Fatima | 13 | JSS 2 |
Let's understand the table:
For example, Tunde's complete information is one record. His age of 13 is one value stored in the Age field.
SQL stands for Structured Query Language. It is a language used to communicate with relational databases.
Just as humans use English, Yoruba, or Hausa to communicate, database users can use SQL to communicate with databases.
SQL allows us to:
For example, a school administrator can use SQL to find all students registered in JSS 2.
Example of a simple SQL query:
SELECT * FROM Students;
This command tells the database to display all the information stored in the Students table.
Don't worry if this command looks strange. You will learn how to write SQL commands step by step in the coming modules.
Database queries make it easier and faster to find information. Imagine how difficult it would be for a bank to search through millions of customer records manually!
Here are some places where database queries are useful:
Without database queries, finding information in large databases would be much more difficult.
There are different types of database queries. Each type performs a different task.
1. SELECT Query
Used to retrieve or display information from a database.
SELECT * FROM Students;
2. INSERT Query
Used to add new information to a database.
INSERT INTO Students (Name, Age)
VALUES ('Tunde', 13);
3. UPDATE Query
Used to change information that already exists.
UPDATE Students
SET Age = 14
WHERE Name = 'Tunde';
4. DELETE Query
Used to remove information from a database.
DELETE FROM Students
WHERE Name = 'Tunde';
Important: DELETE and UPDATE commands can affect important records. Always check your conditions carefully before using them.
A relational database is a type of database that stores information in different tables that can be connected to one another.
For example, a school database may contain:
These tables can be connected using common values such as Student ID or Teacher ID.
Imagine that Tunde has Student ID 101. His name and age may be stored in the Students table, while his Mathematics score is stored in the Results table. The Student ID helps the database connect the information.
This makes it easier to organise information without putting everything into one large table.
Imagine you are helping your school administrator organise student information.
Study the table below:
| ID | Name | Age | Class |
|---|---|---|---|
| 201 | John | 13 | JSS 2 |
| 202 | Mary | 12 | JSS 1 |
| 203 | Peter | 14 | JSS 3 |
| 204 | Aisha | 13 | JSS 2 |
Answer these questions:
In this module, you have learned that:
Test your understanding of this module by answering the following questions.
You have completed Module 1 of Basic Queries. You are now ready to learn more about SQL and how to communicate with databases.
Up Next: Module 2 โ Understanding SQL Fundamentals.
CRMNuggets โ Learn. Practice. Get Certified.