We use cookies to enhance your experience on the site
CodeWorlds

Your first spell: SELECT

Time to give the Library its first order! The most important command in SQL is SELECT - "show me the data".

All columns: SELECT *

The asterisk

*
means "all columns":

1SELECT * FROM ksiazki;

This means: "Show all fields of all books on the ksiazki shelf". The Library will return the entire contents of the shelf.

Selected columns

Usually we don't need everything. We can ask only for specific fields, listing them separated by commas:

1SELECT tytul, autor_id FROM ksiazki;

This means: "Show only the title and the

autor_id
(the cross-reference to the author) of each book". The rest of the fields will be omitted. In the
ksiazki
shelf we store the author as the
autor_id
column - a cross-reference to the authors shelf.

What does a SELECT query consist of?

1SELECT tytul, rok_wydania   -- WHICH columns you want to see
2FROM ksiazki;               -- FROM WHICH shelf (table)
  • SELECT - the list of columns you want to receive (or
    *
    for all).
  • FROM - the name of the table you are reading from.

Remember: SELECT always goes hand in hand with FROM. Without naming the shelf the Library does not know where to look!

Go to CodeWorlds