SQL Basics
SQL Basics
by Prisca Ezeyinwa
Introduction to Databases and SQL
What is a Database? What is SQL?
A database is an organized collection of data that allows users to SQL (Structured Query Language) is a programming language
efficiently store, retrieve, manage, and analyze information. It's used to communicate with databases. It allows users to perform
like a digital record-keeping system. For example, a university may tasks such as retrieving specific data, inserting new data, updating
have a database to store student details, grades, and course records, and deleting unnecessary data.
registrations.
SQL Management Systems
MySQL PostgreSQL
Open-source, widely used for web applications. Advanced open-source system known for compliance and reliability.
FROM
Specifies the table from which you are retrieving the data.
WHERE
Allows you to filter data based on specific conditions.
Filtering and Sorting Data
Filtering Data Using WHERE Sorting Data Using ORDER BY
The WHERE clause allows us to filter data based on conditions. For The ORDER BY clause sorts the result set. For example: SELECT
example, to find all students from Ghana: SELECT * FROM name, country FROM Students ORDER BY name ASC; (This
Students WHERE country = 'Ghana'; arranges students alphabetically by name.)
Using Aggregate Functions
(SUM, COUNT, AVG)
The GROUP BY clause groups records based on a column. For The HAVING clause filters grouped data. For example: SELECT
example: SELECT country, COUNT(*) FROM Students GROUP BY country, COUNT(*) FROM Students GROUP BY country HAVING
country; (This counts students from each country.) COUNT(*) > 2; (This shows only countries with more than 2
students.)
Final Project: Design and
Query a Database
Design a small database for a real-world problem (e.g., managing a beauty
salon, grocery store, or NGO donations). Write SQL queries to insert, retrieve,
filter, and analyze data. Present your findings.
This project allows you to apply the SQL skills you've learned to solve practical
problems. Good luck!