Sql Cheatsheet
Sql Cheatsheet
SQL queries
SQL Summary: https://www.w3schools.com/sql/sql_examples.asp
SQL operations: https://www.w3schools.com/sql/sql_operators.asp
Select
|
|
Where
|
|
AND, OR and NOT Operators
|
|
ORDER BY
This means that it orders by Country, but if some rows have the same Country, it orders them by CustomerName in descending order:
|
|
IS NULL Operator
|
|
SELECT TOP Clause
|
|
Functions
|
|
Min() Max() Count() Avg() sum()
LIKE Operator
|
|
The percent sign (%) represents zero, one, or multiple characters The underscore sign (_) represents one, single character
Wildcard characters: https://www.w3schools.com/sql/sql_wildcards.asp
IN Operator
|
|
Between, Not Between
|
|
Joins
join xxx on xxx
|
|
Different Types of SQL JOINs:
- (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
UNION Operator
The UNION operator is used to combine the result-set of two or more SELECT statements.
|
|
GROUP BY
Select number of customers from each country
|
|
Group by: Basically Merge same records
HAVING
The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate functions
|
|
Combo: lists if the employees “Davolio” or “Fuller” have registered more than 25 orders:
|
|
Generally, select A, B, Group By A Having B
EXISTS
The EXISTS operator is used to test for the existence of any record in a subquery.
|
|
Comment
--Select all
Practice Problem
LC: 1068: select columns from different tables, join 1581: count 197: comparsion
v1.4.14