Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
โ† Basic Queries in SQL ยท Lesson 2 of 10

Module One

๐Ÿ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
2

MODULE 1: INTRODUCTION TO DATABASE QUERIES

Module Overview

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.

Lesson 1: What Is a Database Query?

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:

  • Show me all the students in JSS 2.
  • Find students who scored above 70 in Mathematics.
  • Show me the name of a student with admission number 1025.

Each of these requests is an example of a database query.

Lesson 2: Understanding Databases and Tables

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:

  • Table: The complete collection of student records.
  • Column: A vertical section containing information such as Name, Age, and Class.
  • Row: A horizontal section containing information about one student.
  • Record: The complete information stored about one student.
  • Field: A single category of information, such as Age or Name.

For example, Tunde's complete information is one record. His age of 13 is one value stored in the Age field.

Lesson 3: What Is SQL?

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:

  • Find information stored in a database.
  • Add new information.
  • Change existing information.
  • Delete information when necessary.
  • Arrange and analyse records.

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.

Lesson 4: Why Are Database Queries Important?

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:

  • Schools: Finding students' names, examination results, and school fees records.
  • Banks: Finding customer details and transaction records.
  • Hospitals: Finding patient records and appointment information.
  • Online Stores: Finding products, prices, and customer orders.
  • Airlines: Finding passenger details and flight bookings.
  • Government Offices: Managing citizen and public service records.

Without database queries, finding information in large databases would be much more difficult.

Lesson 5: Types of Database Queries

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.

Lesson 6: Introduction to Relational Databases

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:

  • A Students table containing student information.
  • A Subjects table containing school subjects.
  • A Results table containing examination scores.
  • A Teachers table containing teacher information.

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.

Practical Activity

Imagine you are helping your school administrator organise student information.

Study the table below:

ID Name Age Class
201John13JSS 2
202Mary12JSS 1
203Peter14JSS 3
204Aisha13JSS 2

Answer these questions:

  1. How many students are listed in the table?
  2. What is the name of the table's first student?
  3. Which column contains the students' ages?
  4. Which students are in JSS 2?
  5. What makes this table a database table?

Module Summary

In this module, you have learned that:

  • A database is an organised collection of information.
  • A query is a request or instruction sent to a database.
  • SQL means Structured Query Language.
  • Tables contain rows and columns.
  • Database queries help people find and manage information quickly.
  • Relational databases connect information stored in different tables.
  • SELECT, INSERT, UPDATE, and DELETE are common SQL commands.

Module Assessment

Test your understanding of this module by answering the following questions.

  1. What is a database?
  2. What is a database query?
  3. What does SQL stand for?
  4. What is the difference between a row and a column?
  5. Which SQL command is used to retrieve information?
  6. Which SQL command is used to add new records?
  7. Which SQL command is used to change existing records?
  8. Which SQL command is used to delete records?
  9. Give two examples of places where database queries are used.
  10. What is a relational database?

Congratulations!

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.

๐Ÿ† Get Certified

๐Ÿ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (โ‚ฆ2,000 or 20,000 coins), and get a verified certificate with your name on it.

๐ŸŽ“ Sign Up to Get Certified
๐Ÿ› ๏ธ Practice Tools
Hands-on simulators & labs - subscription required.
โ†’
๐ŸŽฏ Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
โ†’