
Filtering Your World: Mastering the WHERE Clause
The WHERE clause helps you filter rows in a table. Without it, you get all data. With it, you only get what you need.
Example: Customers table
+----+----------+-------------+
| ID | Name | City |
+----+----------+-------------+
| 1 | Alice | London |
| 2 | Bob | Paris |
| 3 | Charlie | London |
+----+----------+-------------+
Query:
SELECT * FROM Customers
WHERE City = 'London';
Result:
+----+--------+--------+
| ID | Name | City |
+----+--------+--------+
| 1 | Alice | London |
| 3 | Charlie| London |
+----+--------+--------+
The Art of Sorting: How to Use ORDER BY Effectively
The ORDER BY clause arranges your results in a chosen order.
Example:
SELECT Name, City
FROM Customers
ORDER BY Name ASC;
ASC
= ascending (A → Z)DESC
= descending (Z → A)
Connecting the Dots: An Introduction to SQL JOINs
JOINs combine data from multiple tables.
Example tables:
Customers
+----+----------+
| ID | Name |
+----+----------+
| 1 | Alice |
| 2 | Bob |
+----+----------+
Orders
+----+-------------+------------+
| ID | Customer_ID | Product |
+----+-------------+------------+
| 1 | 1 | Laptop |
| 2 | 2 | Phone |
| 3 | 1 | Keyboard |
+----+-------------+------------+
Query (JOIN):
SELECT Customers.Name, Orders.Product
FROM Customers
INNER JOIN Orders
ON Customers.ID = Orders.Customer_ID;
Result:
+-------+----------+
| Name | Product |
+-------+----------+
| Alice | Laptop |
| Bob | Phone |
| Alice | Keyboard |
+-------+----------+
INNER JOIN vs. OUTER JOIN: A Simple, Clear Explanation
INNER JOIN → only matching rows from both tables
LEFT OUTER JOIN → all rows from the left table + matching from right
RIGHT OUTER JOIN → all rows from the right table + matching from left
Beyond SELECT *: Choosing Specific Columns for Better Performance
SELECT *
grabs all columns. But in real projects, you usually only need a few.
Bad practice:
SELECT * FROM Customers;
Better practice:
SELECT Name, City FROM Customers;
This makes queries faster and results clearer.
✅ Pro Tip
Avoid always using SELECT *
. It may seem easier, but it slows down your queries and returns unnecessary data. Choose only the columns you really need.