We use cookies to enhance your experience on the site
CodeWorlds

Choosing columns - only what you need

At the Gate location you met the asterisk

*
. It is convenient, but it carries scrolls you never wanted.

SELECT * - the whole shelf

1SELECT * FROM ksiazki;

The Library returns all fields:

id
,
tytul
,
autor_id
,
kategoria_id
,
rok_wydania
,
cena
,
dostepna
. Often that is too much - like asking the scribe for an entire cabinet when you need a single card.

Selected columns - thrift and order

When you name the fields separated by commas, you get exactly what you want:

1SELECT tytul, cena FROM ksiazki;

This means: "Show me the title and price of every book - nothing more".

Why choose specific columns?

  • Readability - the result holds only the relevant fields.
  • Speed - the Library does not haul unnecessary data.
  • Control - you decide the order of the fields in the answer.

The order of columns in the result follows the order on the SELECT list:

1SELECT cena, tytul FROM ksiazki;

Here the price appears before the title. You can name as many fields as you like - two, three, however many - as long as they are separated by commas:

1SELECT tytul, cena, rok_wydania FROM ksiazki;

Leave the asterisk for a quick scouting glance over an unknown shelf; in daily work, choose your fields deliberately.

Go to CodeWorlds