Ściągawka SQL z poleceniami i Descriptjon (2026)

⚡ Inteligentne podsumowanie

This SQL Cheat Sheet collects the commands a working developer reaches for daily, arranged by task. Each section pairs the exact syntax with a plain description, covering database creation, data types, querying, filtering, joining, and indexing.

  • 🗄️ Structure Commands: CREATE DATABASE, CREATE TABLE, ALTER, RENAME and DROP define and reshape the schema.
  • 🔢 Typy danych: Numeric, text, date and binary types set the storage size and valid range of every column.
  • 🔎 Retrieval Commands: SELECT with WHERE, IN, LIKE and REGEXP narrows a result set to the rows that matter.
  • ✍️. Modification Commands: INSERT, UPDATE and DELETE change stored rows, and each accepts an optional condition.
  • 📊 Aggregation Commands: GROUP BY with COUNT, MIN, MAX, SUM and AVG summarises data, and HAVING filters the groups.
  • 🔗 Combination Commands: JOIN merges tables side by side, while UNION stacks the results of two queries.

Ściągawka SQL

Tworzenie poleceń bazy danych i tabeli

Every SQL session starts with a database and at least one table to hold the rows.

Command OPIS
CREATE DATABASE database1; Utwórz bazę danych
CREATE DATABASE IF NOT EXISTS database1; IF NOT EXISTS lets you instruct MySQL server to check the existence of a database with a similar name prior to creating the database.
CREATE DATABASE IF NOT EXISTS database1 CHARACTER SET latin1 COLLATE latin1_swedish_ci; The latin1 character set uses the latin1_swedish_ci collation, which is the Swedish case insensitive order.
SHOW DATABASES; You can see a list of existing databases by running this SQL command.
CREATE TABLE [IF NOT EXISTS] TableName (fieldname dataType [optional parameters]) ENGINE = storage Engine; Utwórz składnię tabeli

Ściągawka dotycząca typów danych SQL

The data type of a column fixes what it can store and how much space each row consumes.

Liczbowe typy danych

Command OPIS
TINYINT( ) -128 to 127 normal, 0 to 255 UNSIGNED.
SMALLINT( ) -32768 do 32767 w normie
0 do 65535 BEZ PODPISU.
MEDIUMINT( ) -8388608 do 8388607 w normie
0 do 16777215 BEZ PODPISU.
INT( ) -2147483648 do 2147483647 w normie
0 do 4294967295 BEZ PODPISU.
BIGINT( ) -9223372036854775808 do 9223372036854775807 w normie
0 do 18446744073709551615 BEZ PODPISU.
FLOAT Mała przybliżona liczba ze zmiennym przecinkiem dziesiętnym.
DOUBLE( , ) A large approximate number with a floating decimal point.
DECIMAL( , ) An exact fixed-point number. The preferred choice for storing currency values.

Typy danych tekstowych

Command OPIS
CHAR( ) A fixed length section from 0 to 255 characters long.
VARCHAR( ) A variable length section from 0 to 65535 characters long.
TINYTEXT Ciąg o maksymalnej długości 255 znaków.
TEXT Ciąg o maksymalnej długości 65535 znaków.
BLOB Binary data with a maximum length of 65535 bytes.
MEDIUMTEXT Ciąg o maksymalnej długości 16777215 znaków.
MEDIUMBLOB Binary data with a maximum length of 16777215 bytes.
LONGTEXT Ciąg o maksymalnej długości 4294967295 znaków.
LONGBLOB Binary data with a maximum length of 4294967295 bytes.

Typy danych Data/Czas

Command OPIS
DATE RRRR-MM-DD
DATETIME RRRR-MM-DD GG: MM: SS
TIMESTAMP YYYY-MM-DD HH:MM:SS, stored in UTC and converted to the session time zone.
TIME GG:MM:SS

Inne typy danych

Command OPIS
ENUM To store one text value chosen from a list of predefined text values.
SET This is also used for storing text values chosen from a list of predefined text values. It can hold multiple values.
BOOL Synonym for TINYINT(1), used to store Boolean values.
BINARY Similar to CHAR; the difference is that text is stored in binary format.
VARBINARY Similar to VARCHAR; the difference is that text is stored in binary format.

Polecenie instrukcji SQL SELECT

SELECT is the command used to read rows back out of a table.

Command OPIS
SELECT * FROM table1; Select every column from the table
SELECT t1, t2, t3, t4 FROM table1; We are only interested in getting the t1, t2, t3 and t4 fields.
SELECT CONCAT(t1, ' (', t3, ')'), t4 FROM table2; Joining column values into a single output column
SELECT column_name | value | expression [AS] alias_name; Składnia nazw pól aliasów

Klauzula SQL WHERE z poleceniami AND, OR, IN, NOT IN

The WHERE clause filters rows, and the operators below can be combined inside it.

Command OPIS
SELECT * FROM tableName WHERE condition; WHERE clause syntax
SELECT * FROM table1 WHERE t1 = 2 AND t2 = 2008; WHERE clause combined with the AND logical operator
SELECT * FROM table1 WHERE t1 = 1 OR t1 = 2; WHERE clause combined with the OR logical operator
SELECT * FROM table2 WHERE t1 IN (1,2,3); WHERE clause combined with the IN keyword
SELECT * FROM table2 WHERE t1 NOT IN (1,2,3); WHERE clause combined with the NOT IN keyword
SELECT * FROM table2 WHERE t3 = 'Female'; WHERE clause combined with the equal (=) comparison operator
SELECT * FROM table3 WHERE t3 > 2000; WHERE clause combined with the greater than (>) comparison operator
SELECT * FROM table1 WHERE t1 <> 1; WHERE clause combined with the not equal to (<>) comparison operator

Polecenie SQL WSTAW DO tabeli

Command OPIS
INSERT INTO table_name(column_1, column_2, ...) VALUES (value_1, value_2, ...); Basic syntax of the SQL INSERT command
INSERT INTO table1 (t1,t2,t3,t4) VALUES (X1,X2,X3,X4); Insert data into a table
INSERT INTO table_1 SELECT * FROM table_2; Inserting into a table from another table

Polecenie SQL DELETE

Command OPIS
DELETE FROM table_name [WHERE condition]; Usuń wiersz w MySQL

Polecenie aktualizacji SQL

Command OPIS
UPDATE table_name SET column_name = new_value [WHERE condition]; Update command syntax

ORDER BY w SQL: polecenie DESC i ASC

Command OPIS
SELECT statement... [WHERE condition | GROUP BY field_name(s) HAVING condition] ORDER BY field_name(s) [ASC | DESC]; ORDER BY clause basic syntax
SELECT {fieldName(s) | *} FROM tableName(s) [WHERE condition] ORDER BY fieldname(s) ASC | DESC [LIMIT N]; Składnia DESC i ASC

Polecenie SQL GROUP BY i HAVING

GRUPUJ WEDŁUG collapses rows into groups, and HAVING filters those groups after they are formed.

Grupuj według

Command OPIS
SELECT statements... GROUP BY column_name1[, column_name2, ...] [HAVING condition]; GROUP BY syntax

Grouping i funkcje agregujące

Command OPIS
SELECT t2, COUNT(t1) FROM table1 GROUP BY t2; Załóżmy, że chcemy mieć w naszej bazie danych całkowitą liczbę wartości kolumn t2.

Klauzula HAVING

Command OPIS
SELECT * FROM table2 GROUP BY t1_id, t4 HAVING t1_id = x1; Returns all the t4 values for table2 rows whose t1_id is x1.

Polecenia SQL typu Wildcards dla Like, NOT Like, Escape, (%), ( _)

Wildcards let LIKE match partial strings.

% the percentage wildcard command in MySQL

Command OPIS
SELECT statements... WHERE fieldname LIKE 'xxx%'; Basic syntax for the % percentage wildcard, which matches any number of characters

_ polecenie podkreślenia symbolu wieloznacznego

Command OPIS
SELECT * FROM table1 WHERE t3 LIKE 'x2_'; The underscore matches exactly one character.

NIE Podobnie jak polecenie wieloznaczne

Command OPIS
SELECT * FROM table1 WHERE t3 NOT LIKE 'x2_'; Suppose we want the table1 rows whose t3 value does not match the pattern.

Polecenie ucieczki słowa kluczowego ze znakiem wieloznacznym

Command OPIS
LIKE '67#%' ESCAPE '#'; Checks for the literal string “67%”, because # escapes the wildcard.

Wyrażenia regularne SQL (REGEXP)

Command OPIS
SELECT statements... WHERE fieldname REGEXP 'pattern'; Basic syntax of a regular expression match

Wyrażenie regularne Metaznaki

Command OPIS
* The asterisk (*) metacharacter matches zero or more instances of the string preceding it.
+ The plus (+) metacharacter matches one or more instances of the string preceding it.
? The question mark (?) metacharacter matches zero or one instance of the string preceding it.
. The dot (.) metacharacter matches any single character except a new line.
[abc] The charlist [abc] matches any of the enclosed characters.
[^abc] The charlist [^abc] matches any character excluding the ones enclosed.
[A-Z] The [A-Z] range matches any upper case letter.
[a-z] The [a-z] range matches any lower case letter.
[0-9] The [0-9] range matches any digit from 0 through to 9.
^ The caret (^) anchors the match at the beginning.
| The vertical bar (|) isolates alternatives.
[[:<:]] The [[:<:]] marker matches the beginning of words.
[[:>:]] The [[:>:]] marker matches the end of words.
[:class:] The [:class:] marker matches a character class, for example [:alpha:] for letters, [:space:] for white space, [:punct:] for punctuation and [:upper:] for upper case letters.

Polecenia funkcji SQL

Funkcje ciągów

Command OPIS
SELECT t1_id, t2, UCASE(t2) FROM table1; The UCASE function takes a string as a parameter and converts all the letters to upper case.

Funkcje numeryczne

Command OPIS Przykład
DIV Dzielenie liczb całkowitych SELECT 23 DIV 6;
/ podział SELECT 23 / 6;
- Podłożetraccja SELECT 23 - 6;
+ Dodatek SELECT 23 + 6;
* Mnożenie SELECT 23 * 6 AS multiplication_result;
% or MOD Moduł SELECT 23 % 6; or SELECT 23 MOD 6;
FLOOR Removes the decimal places from a number and rounds it down to the nearest whole number. SELECT FLOOR(23 / 6) AS floor_result;
ROUND Rounds a number with decimal places to the nearest whole number. SELECT ROUND(23 / 6) AS round_result;

Przechowywane funkcje

Command OPIS
CREATE FUNCTION sf_name ([parameter(s)]) Mandatory. Tells MySQL server to create a function named sf_name with the optional parameters defined in the parentheses.
RETURNS data type Mandatory. Specifies the data type that the function returns.
DETERMINISTIC The function returns the same value whenever the same arguments are supplied to it.
STATEMENTS Kod proceduralny wykonywany przez funkcję.

Polecenia funkcji agregującej SQL

Command OPIS
SELECT COUNT(t1_id) FROM table1 WHERE t1_id = 2; funkcja LICZENIE
SELECT MIN(t3) FROM table2; Funkcja MIN
SELECT MAX(t3) FROM table2; Funkcja MAX
SELECT SUM(t4) FROM table3; Funkcja SUM
SELECT AVG(t4) FROM table3; AVG funkcjonować

Polecenia SQL IS NULL & NOT NULL

A NULL is an absent value, so it must be tested with IS NULL rather than the equals operator.

Command OPIS
SELECT COUNT(t3) FROM table1; COUNT ignores NULL values in the column.
CREATE TABLE table2(
t1_number int NOT NULL,
t2_names varchar(255),
t3 varchar(6)
);
NOT NULL forbids empty values in a column.
column_name IS NULL
column_name IS NOT NULL
NULL keywords basic syntax
SELECT * FROM table1 WHERE t2_number IS NULL; Przykład IS NULL
SELECT * FROM table1 WHERE t2_number IS NOT NULL; Przykład NIE JEST NULL

Polecenia SQL AUTO_INCREMENT

Command OPIS
CREATE TABLE table1 (
t1_id int(11) AUTO_INCREMENT,
t2_name varchar(150) DEFAULT NULL,
t3 varchar(500) DEFAULT NULL,
PRIMARY KEY (t1_id)
);
Składnia automatycznego zwiększania

SQL – ZMIEŃ, UPUŚĆ, ZMIEŃ NAZWĘ, MODYFIKUJ

These commands change a table that already contains data.

Command OPIS
ALTER TABLE table_name ADD COLUMN column_name data_type; ALTER syntax
DROP TABLE sample_table; Składnia DROP TABLE
RENAME TABLE current_table_name TO new_table_name; RENAME command syntax
ALTER TABLE table1 CHANGE COLUMN t1_names t1name char(250) NOT NULL; CHANGE keyword
ALTER TABLE table1 MODIFY t1name char(50) NOT NULL; MODIFY keyword
ALTER TABLE table1 ADD t4 date NULL AFTER t3; AFTER keyword

LIMIT I PRZESUNIĘCIE SQL

Command OPIS
SELECT {fieldname(s) | *} FROM tableName(s) [WHERE condition] LIMIT N; Składnia słowa kluczowego LIMIT
SELECT * FROM table1 LIMIT 1, 2; Offset in the LIMIT query: skip 1 row, then return 2.

SQL SubQuery commands

Command OPIS
SELECT t1_name FROM table1 WHERE
category_id = (SELECT MIN(t1_id) FROM table2);
Zapytania podrzędne

Polecenia SQL JOINS

ŁĄCZY combine columns from two tables into one result set.

Command OPIS
SELECT * FROM table1 CROSS JOIN table2; Krzyż DOŁĄCZ
SELECT table1.t1, table1.t2, table2.t1
FROM table1, table2
WHERE table2.id = table1.table2_id;
INNER JOIN
SELECT A.t1, B.t2, B.t3
FROM table2 AS A
LEFT JOIN table1 AS B
ON B.table2_id = A.id;
LEFT JOIN
SELECT A.t1, A.t2, B.t3
FROM table1 AS A
RIGHT JOIN table2 AS B
ON B.id = A.table2_id;
WŁAŚCIWE DOŁĄCZENIE
SELECT A.t1, B.t2, B.t3
FROM table2 AS A
LEFT JOIN table1 AS B
USING (table2_id);
Klauzule „ON” i „USING”.

Polecenia UNION SQL

UNION stacks the rows of two queries, whereas a JOIN widens them into more columns.

Command OPIS
SELECT column1, column2 FROM table1
UNION
SELECT column1, column2 FROM table2;
UNION syntax. Duplicate rows are removed.
SELECT column1, column2 FROM table1
UNION ALL
SELECT column1, column2 FROM table2;
UNION ALL keeps duplicate rows.

Polecenia SQL w widokach

odwiedzajacy store a query under a name so it can be reused like a table.

Command OPIS
CREATE VIEW view_name AS SELECT statement; Składnia widoków
DROP VIEW general_v_movie_rentals; Spadekping widoki

Polecenia indeksu SQL

An index is a lookup structure that makes searches on a column far faster.

Command OPIS
CREATE INDEX id_index ON table_name(column_name); Dodaj podstawową składnię indeksu
DROP INDEX index_id ON table_name; Podstawowa składnia indeksu upuść

FAQ

No. Keywords such as SELECT and WHERE work in any case. Uppercase is a convention separating commands from identifiers. Table names, however, can be case sensitive on Linux.

DELETE removes selected rows and can be rolled back. TRUNCATE empties the whole table quickly and resets AUTO_INCREMENT. DROP removes the table definition itself.

FROM and JOIN run first, then WHERE, GROUP BY, HAVING, SELECT, ORDER BY and finally LIMIT. This is why a column alias defined in SELECT cannot be used inside WHERE.

Yes. Text-to-SQL assistants translate a question into a query using the table schema. Always read the generated WHERE and JOIN conditions, because a plausible query can return wrong rows.

Tak. Reviewing AI output, tuning slow queries and reading an execution plan all demand fluency in the commands. A reference sheet speeds recall; it does not replace understanding.

Podsumuj ten post następująco: