Вы находитесь на странице: 1из 3

SQL SELECT

SELECT column1, column2, ...


FROM table_name;

SQL SELECT DISTINCT no repeating values

SELECT DISTINCT column1, column2, ...


FROM table_name;

SQL SELECT TOP

SELECT TOP number|percent column_name(s)


FROM table_name
WHERE condition;

SQL WHERE

SELECT column1, column2, ...


FROM table_name
WHERE condition;

SQL AND | OR

SELECT column1, column2, ...


FROM table_name
WHERE condition1 AND | OR condition2 AND | OR condition3 ...;

SQL NOT

SELECT column1, column2, ...


FROM table_name
WHERE NOT condition;

SQL ORDER BY

SELECT column1, column2, ...


FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

SQL INSERT INTO

INSERT INTO table_name (column1, column2, column3, ...)


VALUES (value1, value2, value3, ...);

SQL NULL

SELECT column_names
FROM table_name
WHERE column_name IS NULL;

SQL UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

SQL DELETE

DELETE FROM table_name


WHERE condition;
SQL MIN | MAX returns the biggest/smallest value of the selected column

SELECT MIN | MAX(column_name)


FROM table_name
WHERE condition;

SQL COUNT - returns the number of rows that matches a specified criterion.

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

SQL SUM | AVG - returns the average value/sum of a numeric column.

SELECT SUM | AVG(column_name)


FROM table_name
WHERE condition;

SQL LIKE

SELECT column1, column2, ...


FROM table_name
WHERE columnn LIKE pattern;

SQL WILDCARD CHARACTERS

[charlist] - Defines sets and ranges of characters to match


[!charlist] - Defines sets and ranges of characters NOT to match
% - The percent sign represents zero, one, or multiple characters
_ - The underscore represents a single character

SQL IN - allows you to specify multiple values in a WHERE clause.

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);

SQL BETWEEN

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

SQL ALIAS (COLUMN)

SELECT column_name AS alias_name


FROM table_name;

SQL ALIAS (TABLE)

SELECT column_name(s)
FROM table_name AS alias_name;
SQL JOINS

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate


FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Return all records from the left table, and the matched
records from the right table
RIGHT (OUTER) JOIN: Return all records from the right table, and the matched
records from the left table
FULL (OUTER) JOIN: Return all records when there is a match in either left or
right table

Вам также может понравиться