Structured Query Language
Structured Query Language
SQL
What is SQL?
SQL IN Clause
SELECT column1, column2....columnN
FROM table_name
WHERE column_name IN (val-1, val-2,...valN);
SQL BETWEEN Clause
SELECT column1, column2....columnN
FROM table_name
WHERE column_name BETWEEN val-1 AND val-2;
SQL LIKE Clause
SELECT column1, column2....columnN
FROM table_name
Various Syntax in SQL
SQL ORDER BY Clause
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION
ORDER BY column_name {ASC|DESC};
SQL GROUP BY Clause
SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
GROUP BY column_name;
SQL COUNT Clause
SELECT COUNT(column_name)
FROM table_name
Various Syntax in SQL
SQL HAVING Clause
SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
GROUP BY column_name
HAVING (arithmetic function condition);
TINYINT 0 255
TIMESTAMP Stores number of seconds passed since the Unix epoch ('1970-01-
01 00:00:00' UTC)
= Checks if the values of two operands are equal or not, if yes then condition becomes true. (a = b) is not true.
Checks if the values of two operands are equal or not, if values are not equal then condition
!= becomes true. (a != b) is true.
Checks if the values of two operands are equal or not, if values are not equal then condition
<> becomes true. (a <> b) is true.
Checks if the value of left operand is greater than the value of right operand, if yes then
> condition becomes true. (a > b) is not true.
Checks if the value of left operand is less than the value of right operand, if yes then condition
< becomes true. (a < b) is true.
Checks if the value of left operand is greater than or equal to the value of right operand, if yes
>= then condition becomes true. (a >= b) is not true.
Checks if the value of left operand is less than or equal to the value of right operand, if yes
<= then condition becomes true. (a <= b) is true.
Checks if the value of left operand is not less than the value of right operand, if yes then
!< condition becomes true. (a !< b) is false.
Checks if the value of left operand is not greater than the value of right operand, if yes then
!> condition becomes true. (a !> b) is true.
SQL Logical Operators
ALL - The ALL operator is used to compare a value to all values in another value set.
AND - The AND operator allows the existence of multiple conditions in an SQL
statement's WHERE clause.
ANY - The ANY operator is used to compare a value to any applicable value in the list
as per the condition.
BETWEEN - The BETWEEN operator is used to search for values that are within a set
of values, given the minimum value and the maximum value.
EXISTS - The EXISTS operator is used to search for the presence of a row in a
specified table that meets a certain criterion.
IN - The IN operator is used to compare a value to a list of literal values that have
been specified.
LIKE - The LIKE operator is used to compare a value to similar values using wildcard
operators.
SQL Logical Operators
NOT
The NOT operator reverses the meaning of the logical operator with which it is used.
Eg: NOT EXISTS, NOT BETWEEN, NOT IN, etc. This is a negate operator.
OR
The OR operator is used to combine multiple conditions in an SQL statement's
WHERE clause.
IS NULL
The NULL operator is used to compare a value with a NULL value.
UNIQUE
The UNIQUE operator searches every row of a specified table for uniqueness (no
duplicates).
Some examples