Lab 01 — SELECT & FROM
Ask your first question of a database. Learn to choose columns, rename them, and compute new ones.
📖 Concept Recap: SELECT & FROM
- SELECT tells SQL which columns to return.
- FROM tells SQL which table to read.
SELECT *returns every column in the table.- List specific column names separated by commas to select only those columns.
- Use AS to rename a column in the output (alias):
gpa * 4 AS scaled_score. - You can compute math expressions directly in SELECT:
gpa * year. - Every SQL statement ends with a semicolon (
;).
👀 Worked Example (read-only)
Study these queries before writing your own.
-- Get everything from the table SELECT * FROM students; -- Select specific columns only SELECT name, major, gpa FROM students; -- Computed column with an alias SELECT name, gpa, gpa * 4 AS scaled_score FROM students;
Exercise 1 — Your First SELECT
Show the name and city of all students. Replace each ___ with the correct column name.
Exercise 2 — Multiple Columns with an Alias
Show name, major, year, and scholarship for all students. Rename the scholarship column as on_scholarship using AS.
SELECT col1, col2, col3, col4 AS new_name FROM table;Exercise 3 — Computed Column
Calculate a weighted_score = gpa * year. Show name, gpa, year, and weighted_score. Students who stay longer and maintain high GPA score highest.
gpa * year AS weighted_scoreMini Project — Understanding the Student Population
You are a new academic advisor. Write 3 different SELECT queries to get to know the students table. Run each one individually by selecting and running, or run all at once.
- The full roster — every column, every row.
- Key identifiers only — name, major, and year.
- An interesting calculated field (e.g.,
gpa / 4.0 * 100 AS gpa_percentorage - 18 AS years_since_hs).
🏁 Lab 01 Complete!
You can now write SELECT queries to retrieve any combination of columns from a table, create aliases, and compute new columns on the fly.
Ready for the next challenge?
Continue to Lab 02 — WHERE →