Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Jose Pérez García Chuletari

SELECT DISTINCT Country FROM Customers – only distinct values

SELECT * FROM Customers; - all

SELECT column1, column2, ...

FROM table_name

WHERE condition; - that has a specified condition

SELECT * FROM Customers

WHERE CustomerID=1;

= Equal

Between – shearch values “entre” \like search specific pattern \in multiply values for

column

WHERE "nombre_columna" BETWEEN 'valor1' AND 'valor2';

SELECT * FROM Customers

w here not ci

='

berlin

';

SELECT MIN(column_name) – return min value/max value

FROM table_name

WHERE condition;

SELECT AVG(column_name) - returns the average value of a numeric column.

FROM table_name

WHERE condition;

Daniel Sánchez Aranega Chuletari _Uf2_Part1

SELECT SUM(column_name) - returns the total sum of a numeric column. FROM table_name
WHERE condition;

SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern;

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

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


value2;

SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;


A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.

The INNER JOIN keyword selects records that have matching values in both tables.

The LEFT JOIN keyword returns all records from the left table (table1), and the matched
records from the right table (table2). The result is NULL from the right side, if there is no
match.

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


JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

SELECT column_name(s) FROM table1 INNER JOIN table2 \ LEFT JOIN table2 \ RIGHT JOIN
table2 ON table1.column_name = table2.column_name;

The ANY and ALL operators are used with a WHERE or HAVING clause.

The ANY operator returns true if any of the subquery values meet the condition.

The ALL operator returns true if all of the subquery values meet the condition.

SELECT column_name(s) FROM table_name WHERE column_name operator ANY / ALL


(SELECT column_name FROM table_name WHERE condition);

SELECT COUNT(DISTINCT Country) FROM Customers; - count distinct ex 97

Where not, where… and …and, where… or….or

SELECT column1, column2, ...

FROM table_name

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

SELECT * FROM Customers

ORDER BY Country;

SELECT * FROM Customers

ORDER BY Country, CustomerName;

SELECT * FROM Customers

ORDER BY Country ASC, CustomerName DESC;

SELECT column_names

FROM table_name

WHERE column_name IS NOT NULL;

You might also like