SQL FOUNDATIONS:SELECT & Basic Queries
Learn SELECT basics, column order, aliases, and DISTINCT.
What is SELECT
The SELECT statement is used to retrieve data from a table. It is the most fundamental SQL command and is used in almost every query.
Basic Syntax
sqlSELECT column1, column2FROM table_name;
SELECTspecifies the columns to retrieveFROMspecifies the table
Example Dataset
Table: employees
Selecting All Columns
sqlSELECT * FROM employees;
This retrieves all columns and all rows from the table.
Selecting Specific Columns
sqlSELECT name, salary FROM employees;
This retrieves only the name and salary columns.
Column Order Matters
sqlSELECT salary, name FROM employees;
The output will display columns in the same order as written in the query.
Using Aliases (Renaming Columns)
sqlSELECT name AS employee_name, salary AS incomeFROM employees;
ASis used to rename columns in the output- Useful for readability and reporting
Removing Duplicate Values with DISTINCT
sqlSELECT DISTINCT department FROM employees;
This returns only unique department values.
Key Concepts
SELECT *is useful for exploration but not recommended in production- Always select only required columns for efficiency
- Use
DISTINCTwhen you need unique values - Use aliases to make results clearer
SELECT & Basic Queries Missions
Solve exercises in sequence to unlock the next mission.
1
2
Select name and department
Retrieve only the name and department columns.
Locked
3
Salary then name
Retrieve salary and name, in that order.
Locked
4
Rename name column
Rename the column name to employee_name.
Locked
5
Distinct departments
Retrieve unique department values.
Locked
6
Salary only
Retrieve only the salary column.
Locked
7
Rename salary as income
Retrieve name and salary, and rename salary as income.
Locked