🏆 OSM

Core SQL Querying Skills for Beginners: WHERE, ORDER BY, and JOINs Explained Simply

2 weeks ago
2025-09-04 11:21:00

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;

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


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.

Previous Blog

SQL Basics for Beginners: A Simple Guide to Your First Database Query

Next Blog

SQL Data Manipulation and Definition Basics: INSERT, UPDATE, DELETE, CREATE TABLE, and Keys Explained

© 2025 Oscar Myo Min

Design by Kai

𝕏 GitHub