SQL 1
SQL 1
FROM table_name
WHERE condition;
WHERE CustomerID=1;
AND Statement
SELECT * FROM Customers
OR Statement
NOT Statement
The following SQL statement selects all fields from "Customers" where country is
NOT "Germany":
SQL ORDER BY
The ORDER BY keyword sorts the records in ascending order by default. To sort
the records in descending order, use the DESC keyword.
ORDER BY Country;
Descending Order
NULL Value
The term NULL in SQL is used to specify that a data value does not exist in the
database. It is not the same as an empty string or a value of zero, and it signifies
the absence of a value or the unknown value of a data field.
It is important to understand that you cannot use comparison operators such as “=”,
“<”, or “>” with NULL values. This is because the NULL values are unknown and
could represent any value.
UPDATE Customers
WHERE Country='Mexico';
WHERE Country='Germany'
FROM table_name
The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.
SELECT MAX(column_name)
FROM table_name
WHERE condition;
COUNT() Syntax
The COUNT() function returns the number of rows that matches a specified
criterion
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
AVG() Syntax
The AVG() function returns the average value of a numeric column.
SELECT AVG(column_name)
FROM table_name
WHERE condition;
SUM() Syntax
SELECT SUM(column_name)
FROM table_name
WHERE condition;
SQL IN Operator
SQL Aliases
SQL aliases are used to give a table, or a column in a table, a temporary name.
Aliases are often used to make column names more readable.
FROM Customers;
SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related
column between them.
(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Returns all records from the left table, and the matched
records from the right table
RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched
records from the left table
FULL (OUTER) JOIN: Returns all records when there is a match in either left or
right table
The INNER JOIN keyword selects records that have matching values in both
tables.
SELECT column_name(s)
FROM table1
ON table1.column_name = table2.column_name;
SQL LEFT JOIN
The LEFT JOIN keyword returns all records from the left table (table1), and the
matching records from the right table (table2). The result is 0 records from the
right side, if there is no match.
SELECT column_name(s)
FROM table1
ON table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1
ON table1.column_name = table2.column_name;
The UNION operator is used to combine the result-set of two or more SELECT
statements.
1. Every SELECT statement within UNION must have the same number of
columns.
2. The columns must also have similar data types
UNION
The SELECT INTO statement copies data from one table into a new table.
FROM Customers;