πΉ SELECT Command
Definition: The SELECT
statement is used to fetch data from a database table. It's the most commonly used SQL command.
Syntax:
SELECT column1, column2, ...
FROM table_name;
π Sample Table: students
id | name | age | grade |
1 | Asha | 15 | A |
2 | Rohan | 14 | B |
3 | Meena | 16 | A |
π’ Output: Shows all data from the students
table.
id | name | age | grade |
1 | Asha | 15 | A |
2 | Rohan | 14 | B |
3 | Meena | 16 | A |
SELECT name, grade FROM students;
π’ Output: Only shows name and grade for each student.
name | grade |
Asha | A |
Rohan | B |
Meena | A |
π When to Use SELECT:
Use SELECT when you want to retrieve data from one or more columns in a table. Itβs the foundation of all read operations in SQL.
β οΈ Common Mistakes:
- Using
SELECT
without FROM
β causes an error.
- Missing commas:
SELECT name grade
instead of SELECT name, grade
.
- Spelling table or column names incorrectly.