Posted on: Fri Jun 06 2025
Author: Ignatius Emeka
SQL is a language used to interact with relational databases, which store data in tables with rows and columns. You can use SQL to:
Why Learn SQL? It’s in high demand for roles like data analyst, business intelligence developer, and backend engineer. SQL’s simplicity makes it perfect for beginners.
A query is an SQL command to interact with a database. The most common query is SELECT, which retrieves data from tables.
SELECT column_name FROM table_name WHERE condition;
SELECT
: Specifies the columns to retrieve.FROM
: Names the table.WHERE
: Filters rows based on conditions.Let’s query a table called employees
with columns id, name
, and salary
. To get all employee names:
SELECT name FROM employees;
Explanation:
SELECT name
: Retrieves only the name
column.FROM employees
: Targets the employees
table.To find employees with a salary above 50,000:
SELECT name, salary FROM employees WHERE salary > 50000;
Explanation:
SELECT name, salary
: Retrieves two columns.WHERE salary > 50000
: Filters for employees with salaries above 50,000.To list employees alphabetically by name:
SELECT name FROM employees ORDER BY name ASC;
Explanation:
ORDER BY name ASC
: Sorts results in ascending order (A-Z).To find employees named “Alice” with a salary above 50,000:
SELECT name, salary FROM employees WHERE name = 'Alice' AND salary > 50000;
Explanation:
WHERE name = 'Alice' AND salary > 50000
: Combines conditions with AND
.Let’s create a program to query a products
table (columns: product_id
, product_name
, price
) and find products priced between 20 and 100.
SELECT product_name, price
FROM products
WHERE price BETWEEN 20 AND 100
ORDER BY price ASC;
How It Works:
SELECT product_name, price
: Retrieves product names and prices.WHERE price BETWEEN 20 AND 100
: Filters for prices in the range.ORDER BY price ASC
: Sorts results by price (lowest to highest).product_name | price
--------------|-------
Book | 25
Headphones | 80
To try these SQL queries:
CREATE DATABASE store; USE store
;products
table:CREATE TABLE products (
product_id INT,
product_name VARCHAR(50),
price DECIMAL(10,2)
);
INSERT INTO products VALUES
(1, 'Book', 25.00),
(2, 'Headphones', 80.00),
(3, 'Laptop', 1200.00);
SQL is foundational for data-driven roles. It powers:
Mastering SQL opens doors to careers in data science, analytics, and more.
PalmTechnIQ’s SQL courses are designed for all levels:
SQL is your gateway to a data-driven career. Visit PalmTechnIQ to enroll in our SQL for Beginners course and master querying in 2025.