The SELECT Statement
The SELECT statement is the most fundamental SQL command. It retrieves data from database tables.
SELECT * Syntax
The asterisk * means "all columns":
sql
1SELECT * FROM table_name;Example: Get All Students
sql
1SELECT * FROM students;Result
| id | name | age | course | marks | grade |
|---|---|---|---|---|---|
| 1 | Alice | 14 | Python | 85 | A |
| 2 | Bob | 12 | JavaScript | 78 | B |
| 3 | Carol | 15 | Python | 92 | A |
| 4 | David | 13 | Ruby | 65 | C |
Breaking Down the Query
SELECT- Command to retrieve data*- All columnsFROM- Specifies the sourcestudents- Table name
When to Use SELECT *
Good for:
- Quick data exploration
- Small tables
- Testing queries
Avoid when:
- Large tables (performance)
- Production code (specify columns)
- Joining tables (column confusion)
Best Practice
In production, specify columns explicitly:
sql
1-- Better for production
2SELECT name, age, course FROM students;This makes queries faster and more maintainable.
