DataBolt

All Lessons

Introduction to SQL
SQL Lesson 1: Your Sample Database
SQL Lesson 2: SELECT — Reading data
SQL Lesson 3: WHERE — Filtering rows
SQL Lesson 4: AND, OR, NOT
SQL Lesson 5: BETWEEN, IN, LIKE
SQL Lesson 6: NULL — The Mystery Value
SQL Lesson 7: ORDER BY
SQL Lesson 8: LIMIT & OFFSET
SQL Lesson 9: Aggregate Functions
SQL Lesson 10: GROUP BY
SQL Lesson 11: HAVING
SQL Lesson 12: INNER JOINs
SQL Lesson 13: LEFT JOINs
SQL Lesson 14: RIGHT JOINs
SQL Lesson 15: SELF JOINs
SQL Lesson 16: UNION JOINs
SQL Lesson 17: Joining Multiple Tables
SQL Lesson 18: Subqueries
SQL Lesson 19: CTEs (WITH)
SQL Lesson 20: CASE Statements
SQL Lesson 21: Window Functions
SQL Lesson 22: String Functions
SQL Lesson 23: Date & Time Functions
SQL Lesson 24: INSERT, UPDATE, DELETE
SQL Lesson 25: CREATE TABLE & DDL
SQL Lesson 26: Indexes & Performance
SQL Lesson 27: Transactions & ACID
SQL Lesson 28: SQL Execution Order
SQL Lesson 29: 50 Practice Problems

CHAPTER 2

Your Sample Database

And why is it one of the most valuable skills you can learn in tech?

IN THIS CHAPTER

  • The five tables we will query throughout every chapter
  • How tables relate to each other via primary and foreign keys
  • How to read and interpret a database schema

Table: employees

emp_idnamedepartmentsalarymanager_idhire_date
1ArjunIT850002020-06-15
2PriyaIT7200012021-03-10
3RahulSales5500052022-01-20
4SnehaHR6000052021-07-08
5VikramSales900002019-11-01
6DivyaIT6800012023-02-14
7KiranHR5800042022-08-30
8MeeraSales6200052023-05-12

Table: products

product_idnamecategorypricestock
1iPhone 15Electronics7999950
2SQL BookBooks499200
3HeadphonesElectronics299975
4NotebookStationery99500
5LaptopElectronics6500020
6Pen SetStationery1490
7MouseElectronics59925

Table: customers

customer_idnamecitycountry
1AnanyaHyderabadIndia
2RohanBangaloreIndia
3SamMumbaiIndia
4LisaLondonUK
5RaviDelhiIndia

Table: orders

order_idcustomer_idorder_datetotalstatus
112024-01-1579999completed
222024-01-203498completed
312024-02-1065000completed
432024-02-14499pending
522024-03-01248completed
652024-03-152999shipped
712024-04-05149completed

Table: orders_items

item_idorder_idproduct_idqtyunit_price
111179999
22312999
3221499
435165000
5421499
654299
756150
86312999

How the Tables Connect

Table NameDescriptionKey Columns
orders -> customersorder.customer_idcustomer.customer_id
order_items -> ordersorder_items.order_idorder.order_id
order-items -> productsorder_items.product_idproduct.product_id
employees -> employeesemployees.manager_idemployee.emp_id (self-reference)

How the Tables Connect

Table NameDescriptionKey Columns
orders -> customersorder.customer_idcustomer.customer_id
order_items -> ordersorder_items.order_idorder.order_id
order-items -> productsorder_items.product_idproduct.product_id
employees -> employeesemployees.manager_idemployee.emp_id (self-reference)

💡 Note: Lisa (customer_id 4) has no orders. Pen Set (product_id 6) has stock = 0. These "edge cases" are intentional — they are used to illustrate LEFT JOIN and NULL behaviour in later chapters.