2020-02-28 17:57
Page 1

Databases (TDA357, DIT621)

Lecture 3: SQL 2

Page 2

Last time

Basic SQL

Page 3

Today

More SQL

Page 4

Continue with the same database example

A database with information about countries

Page 5
Continue with the same database example
Page 6
Continue with the same database example
Page 7

PostgreSQL Live demo

Files

Page 8

Aggregations

Page 9

More aggregation examples

Aggregation without using GROUP BY

Page 10

Common currencies

Page 11

Choosing rows based on aggregated values

Page 12

Sets and set operations in math

Page 13

Set operations in relational databases

Page 14
Set operations in relational databases

Places to visit

Page 15
Set operations in relational databases
Page 16
Set operations in relational databases
Page 17

Databases with more than one table

Table schemas

Page 18
Databases with more than one table

SQL

Page 19

Combining tables

Cartesian product (cross product)

Page 20
Combining tables

Inner Join

Page 21
Combining tables

Outer Join

Page 22
Combining tables

Natural Join?

Page 23

Natural Join

An example that makes sense

Page 24
Natural Join → An example that makes sense
Page 25
Natural Join → An example that makes sense
Page 26

Foreign keys

Page 27

Inline constraints vs other constraints

Page 28

Composite keys

Page 29

Views

Page 30

SQL Summary

New things compared to last time

Page 31
SQL Summary

Joins

Page 32

Joins vs cross products

Page 33

Local queries

Page 34

Nested queries

Page 35
Nested queries
Page 36

Alter table

Page 37

That's all for today

Questions?

Wednesday Exercise: SQL

Thursday Lecture: Entity-Relationship modelling