Relational algebra and SQL
הוצג
מילון מונחים
| English | משמעות |
|---|---|
| selection/sɪˈlekʃn/ | בחירה |
| projection/prəˈdʒekʃn/ | A relational-algebra operation choosing specified columns from a relation. |
| join/dʒɔɪn/ | An SQL operation that combines rows from tables according to a specified relationship or condition. |
English
Five operators, one pipeline
- The algebra: selection σ keeps rows, projection π keeps columns, join ⋈ combines on a condition, union and difference combine tables. Every SELECT is these five in a pipeline.

{exercise:uni-cs0802-algebra}
אימונים
The operator that keeps columns is —
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Projection pi keeps the chosen columns; selection sigma keeps rows.
English
Clause order is semantic
- FROM builds the row set, WHERE filters rows, GROUP BY partitions, HAVING filters groups, SELECT projects, ORDER BY sorts. Filtering an aggregate in WHERE is a category error the engine rejects — use HAVING.
- The course query: join Course and Enrollment, select credits = 15, group by title, keep groups of size $\ge 2$. Executed on the sample schema the result is
Databases | 3.
{exercise:uni-cs0802-order}
אימונים
Filtering on COUNT(*) happens in —
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
WHERE filters rows before grouping; HAVING filters the groups.
English
Join flavor decides who survives
- A plain join drops the 2 courses with no enrollment;
LEFT JOINkeeps them withn = 0— 6 rows.COUNT(*)counts rows;COUNT(col)skips NULLs. - Projecting a many-side column repeats values: 14 enrollment rows project 14 student ids — add DISTINCT when you mean the set.
Example
Read every query as a pipeline and the output stops being surprising.
{exercise:uni-cs0802-join}
אימונים
The course query on the sample schema returns —
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
One 15-credit course has 3 enrollments; Algorithms is 12 credits.