Back to Topics

SELECT Queries

Beginner
10 min

What is SELECT Queries?

SELECT queries retrieve data from database tables, allowing you to choose specific columns, filter rows, and sort results.

Key Components:

  • Retrieves data from one or more tables
  • Filters rows with WHERE clause
  • Sorts results with ORDER BY
  • Limits rows for performance

Why it matters

Data Retrieval

Get exactly what you need from databases

Filtering

Find specific records

Sorting

Organize results logically

Performance

Minimize data transfer

Key Concepts

SELECT

Specifies columns

Example: SELECT Name, Email...

FROM

Specifies table

Example: FROM Customers...

WHERE

Filters rows

Example: WHERE City = "Mumbai"...

ORDER BY

Sorts results

Example: ORDER BY Name...

How to use

1

Write SELECT

List columns after SELECT

2

Write FROM

Specify table name

3

Add WHERE

Optional filter condition

4

Add ORDER BY

Optional sorting

5

Add LIMIT

Optional row limit

6

Execute query

Run to see results

Example

Goal: Find customers from Mumbai
SELECT * FROM Customers WHERE City = "Mumbai" ORDER BY Name
Result: All Mumbai customers sorted by name

Pro Tips

  • Avoid SELECT *: Name specific columns
  • Use single quotes: For text values
  • Test with LIMIT: First test with LIMIT 10

Practice

Get all orders over ₹10,000 from the last 30 days