Relation:Tutorial 5

Projection

Project filters the table by columns. You specify the columns you want to keep
We reuse the table films.csv
Look at the code on the right and compare with the result.

Show only the title and the year

film year
A bout de souffle 1960
Tirez sur le pianiste 1960
Cléo de 5 à 7 1962
Jules et Jim 1962
Pierrot le fou 1965
Week-End 1967
Die verlorene Ehre der Katharina Blum 1975
Der starke Ferdinand 1976
Sans toi ni loi 1985

Show only the director

director
Godard
Truffaut
Varda
von Trotta
Kluge

You may notice we only have 4 rows instead of 9. This is because there are only 4 directors for these 9 films. In set theory, there cannot be duplicate values.
NB: In SQL you would get 9 rows, unless you use the DISTINCT option (which you should always).

Show the director first, then the title

director film
Godard A bout de souffle
Truffaut Tirez sur le pianiste
Varda Cléo de 5 à 7
Truffaut Jules et Jim
Godard Pierrot le fou
Godard Week-End
von Trotta Die verlorene Ehre der Katharina Blum
Kluge Der starke Ferdinand
Varda Sans toi ni loi

Project allows you to reorder the columns, too.

Go to Tutorial 6

' ===Projection===

' Project filters the table by columns. You specify the columns you want to keep

' We reuse the table [[Media:films.csv]]

' Look at the code on the right and compare with the result.

' ''''Show only the title and the year'''''

read "films.csv"

project film, year

print

' '''''Show only the director'''''

read "films.csv"

project director

print

' You may notice we only have 4 rows instead of 9. This is because there are only 4 directors for these 9 films. In set theory, there cannot be duplicate values.

' NB: In SQL you would get 9 rows, unless you use the DISTINCT option (which you should always).

' '''''Show the director first, then the title'''''

read "films.csv"

project director, film

print

' Project allows you to reorder the columns, too.

' Go to [[Tutorial 6]]