We use cookies to enhance your experience on the site
CodeWorlds

DISTINCT - unique values only

When you ask a shelf for a single field, the same value repeats many times - many authors come from the same country, many readers from the same city. DISTINCT removes the duplicates.

Without DISTINCT - with repetitions

1SELECT kraj FROM autorzy;

If five authors come from Greece, the word Greece will appear five times.

With DISTINCT - no repetitions

1SELECT DISTINCT kraj FROM autorzy;

Now each country appears only once. It is like the list of sections in the Pinakes - every subject named a single time.

DISTINCT and multiple columns

When you give several fields, DISTINCT removes repeated combinations, not single values:

1SELECT DISTINCT imie, nazwisko FROM czytelnicy;

A row disappears only when first name and surname together are the same as in another row.

Common uses

  • Which cities do readers come from?
    SELECT DISTINCT miasto FROM czytelnicy;
  • Which author countries do we have?
    SELECT DISTINCT kraj FROM autorzy;

DISTINCT is the scribe's sieve - it sifts the scrolls and keeps only the unique catalog cards.

Go to CodeWorlds