Skip to main content
Techlogia — AI and Web Development Berlin
All courses
Free to read – no sign-up

SQL Basics

SELECT, WHERE, INSERT, JOIN, GROUP BY. Write 5 SQL statements into a .sql file. Schema is in the task.

Duration: 30 minLevel: BeginnerExercises: 5

Your first SQL queries

SQL basics: your first queries

SQL (Structured Query Language) is the language for querying and changing databases. Data lives in tables (rows = records, columns = fields). Almost every application stores its data in an SQL database.

Key commands

  • SELECT: query data ("show me …").
  • WHERE: filters rows by a condition.
  • INSERT: adds a new record.
  • JOIN: connects two tables via a shared column.
  • GROUP BY + AVG(): groups rows and computes e.g. averages.

You write the SQL into .sql files under /home/student/sql/ (mkdir -p /home/student/sql). There are tables schueler (name, klasse, …) and noten (fach, note, …).

Your goal

You write five queries — from a simple selection to an analysis across multiple tables.

Exercises

  1. 1. Query all students

    Concept: SELECT. SELECT * FROM table fetches all columns (*) of all rows of a table. Query all students.

    mkdir -p /home/student/sql
    echo "SELECT * FROM schueler;" > /home/student/sql/alle.sql

    Check: alle.sql contains SELECT * FROM schueler.

  2. 2. Students of class 7a

    Concept: WHERE. With WHERE you filter rows by a condition. Fetch only the students of class 7a.

    echo "SELECT * FROM schueler WHERE klasse = '7a';" > /home/student/sql/klasse-7a.sql

    Text values are in single quotes ('7a').

    Check: klasse-7a.sql contains SELECT ... FROM schueler ... WHERE klasse = '7a'.

  3. 3. Insert a new student

    Concept: INSERT. INSERT INTO adds a new record: first the columns, then the values. Add a new student.

    echo "INSERT INTO schueler (name, klasse) VALUES ('Lisa', '7b');" > /home/student/sql/neu.sql

    Check: neu.sql contains INSERT INTO schueler (... name ... klasse ...).

  4. 4. Grades with student name

    Concept: JOIN. A JOIN connects two tables via a shared column (here the student ID), so you can show e.g. grades with the student's name.

    echo "SELECT schueler.name, noten.fach, noten.note FROM schueler JOIN noten ON schueler.id = noten.schueler_id;" > /home/student/sql/noten-mit-namen.sql

    Check: noten-mit-namen.sql contains SELECT ... FROM schueler ... JOIN noten.

  5. 5. Average grade per subject

    Concept: aggregation (AVG + GROUP BY). Aggregate functions combine several rows into one value — AVG() computes the average. GROUP BY fach does it per subject.

    echo "SELECT fach, AVG(note) FROM noten GROUP BY fach;" > /home/student/sql/schnitt.sql

    Check: schnitt.sql contains SELECT ... AVG(note ... GROUP BY fach.

Related courses

Now practice it yourself

Reading is good – doing is better. Start this course on a real Linux VM, right in your browser. A free account is all it takes.

Start for free

Lab content under CC BY 4.0 – free to use with attribution (© TechLogia).

How do you like this page?

SQL Basics | Techlogia Lab