SQL Basics - Getting Started with Databases
Learn SQL fundamentals, SELECT statements, WHERE clauses, and basic database queries

📚 Resources for This Lesson
What is SQL?
SQL (Structured Query Language) is the standard language for managing and manipulating databases. It allows you to create, read, update, and delete data efficiently.
Basic SELECT Statement
The SELECT statement is used to retrieve data from a database.
-- Retrieve all columns from a table
SELECT * FROM employees;
-- Retrieve specific columns
SELECT first_name, last_name, salary FROM employees;
-- Give columns an alias
SELECT first_name AS 'First Name', salary AS 'Annual Salary' FROM employees;
WHERE Clause
Filter data based on specific conditions.
-- Simple condition
SELECT * FROM employees WHERE salary > 50000;
-- Multiple conditions
SELECT * FROM employees WHERE salary > 50000 AND department = 'IT';
-- Using OR
SELECT * FROM employees WHERE department = 'IT' OR department = 'HR';
-- NOT operator
SELECT * FROM employees WHERE NOT department = 'Marketing';
Comparison Operators
=- Equal!=or<>- Not equal>- Greater than<- Less than>=- Greater than or equal<=- Less than or equalBETWEEN- Within a rangeIN- Matches any value in a listLIKE- Pattern matching
LIKE Pattern Matching
-- Starts with 'A'
SELECT * FROM employees WHERE first_name LIKE 'A%';
-- Contains 'John'
SELECT * FROM employees WHERE first_name LIKE '%John%';
-- Ends with 'son'
SELECT * FROM employees WHERE last_name LIKE '%son';
ORDER BY Clause
Sort query results.
-- Sort ascending (default)
SELECT * FROM employees ORDER BY salary;
-- Sort descending
SELECT * FROM employees ORDER BY salary DESC;
-- Sort by multiple columns
SELECT * FROM employees ORDER BY department, salary DESC;
Key Takeaways
- SELECT retrieves data from tables
- WHERE filters data based on conditions
- ORDER BY sorts results
- Master these basics before moving to advanced queries