Alusta SQL-iga

Esimene SELECT Kotomarketis

6 min
What you'll learn
  • kirjutama ja käivitama oma esimese päringu kujul SELECT * FROM products LIMIT 5
  • tulemuse mahtu piirama, muutes LIMIT-is ridade arvu
  • selgitama, miks SELECT on ohutu: see ainult loeb andmeid ega muuda andmebaasis midagi

Kõige olulisem päring

QUERY avab sinu ees arhiivikonsooli — merevaikkollase akna pimedas sektsioonis. Selle taga ootab vaikselt Kotomarketi andmebaas: ostjad, kaubad, tellimused ja käitumissündmused, kõik 2024. aastasse tardunud. Tõmmise lõpust leitud vihje oli selge: alusta SELECT-iga.

Suur osa SQL-tööst algab lihtsast tegevusest: andmete lugemisest. Selleks on käsk SELECT — küsimus, millele andmebaas vastab andmetega: „näita, mis sul on”.

Alustame müügisaalist ja heidame pilgu tabelisse products. Allolev päring palub: „tagasta kõik veerud (*) tabelist products, aga mitte rohkem kui 5 rida”. LIMIT n on siin piirang: see käsib andmebaasil tagastada kuni n rida (ette rutates: sorteerimise kõrval võtame selle põhjalikumalt ette 2. peatükis). Vajuta Käivita — ja müügisaali esimesed read, mis on 160 aastat maganud, ärkavad holopaneelil ellu. Seejärel muuda 5 arvuks 10 ja näed kohe, kuidas tulemuse mahtu juhtida.

QUERY: Vajuta julgelt. SELECT ainult loeb — lugemispäringuga arhiivi ära ei riku. Olen kontrollinud. Korduvalt.

Holograafiline kaubatabel ärkab arhiivikonsooli kohal ellu pärast esimest SELECT-i
Esimene SELECT äratab müügisaali: viis products tabeli rida tõuseb pimedusest holopaneelile.

The single most important query

QUERY unfolds the archive console in front of you — an amber window in the darkness of the bay. Behind it the "Kotomarket" database sits in silence: buyers, products, orders and behavioral events, frozen since 2024. The hint at the end of the was clear: start with SELECT.

Most work with SQL really does begin with one simple act: read the data. That’s what the SELECT command is for — a question the database answers with data: "show me what you’ve got."

Let’s start with the storefront and peek into the products table. The query below asks: "return every column (*) from the products table, but no more than 5 rows." Here LIMIT n is the limiter: it tells the database to return at most n rows (looking ahead — we’ll dig into it properly, together with sorting, in Chapter 2). Hit Run, and the first rows of the storefront, asleep for 160 years, will come alive on the holopanel. Then change 5 to 10 — and you’ll see right away how to control how much the result returns.

QUERY: Go ahead, hit it. SELECT only reads — you can’t spoil the archive with a read query. I’ve tested that. Many times over.

Esimesed 5 kaupa Kotomarketi müügisaalist pärast 160 aastat vaikust:
Query result
idnamecategorypricestock
1Беспроводные наушникиЭлектроника5990.00120
2Смарт-часыЭлектроника8990.0060
3Портативная колонкаЭлектроника3490.0090
4Веб-камера HDЭлектроника2790.0045
5Механическая клавиатураЭлектроника4590.0070
Check yourself
Mida võtmesõna SELECT teeb?