Querying-commands_Reference-Card_Final-3783
Querying-commands_Reference-Card_Final-3783
Querying commands
SELECT
Select specific or all columns from a specified table. SELECT* selects all columns from a table. It is good to use the LIMIT statement, especially
for large tables.
Operators
Operators are used to perform specific operations on one or more operands (values or expressions). Operators are categorised into several
types: comparison operators, logical operators, and others like the LIKE operator and WILDCARD.
Comparison operators
Comparison operators like greater than (>), less than (<), equal to (=), not equal to (<> or !��, more than or equal to (<=) are used with WHERE
to find rows where the outcome of the comparison between a column value and a specified value is TRUE.
LIMIT LIMIT
column1 > value; column1 < value;
WHERE WHERE
column1 = value; column1 != value;
Logical operators
Logical operators are used to combine or negate conditions, determining the overall truth of a condition or a set of conditions.
AND OR
The AND operator combines multiple conditions in a query requiring The OR operator displays a record in a query where either
all conditions to be met for a row to be included in the result set. condition separated by the OR is TRUE.
SELECT SELECT
column1, column1,
column2, column2,
column3 column3
FROM FROM
table_name table_name
LIMIT LIMIT
condition1 condition1
AND condition2; AND condition2;
IN and NOT IN
IN
The IN and NOT IN operators filter data based on a list of specificed values, allowing for inclusion or exclusion of rows that either do or do not
match the provided set of values.
IN NOT IN
SELECT SELECT
column1, column1,
column2, column2,
column3 column3
FROM FROM
table_name table_name
WHERE WHERE
column1 column1
IN NOT IN
( (
value1, value1,
value2, value2,
value3); value3);
IN
BETWEEN
The BETWEEN operator selects rows within a specified range, inclusive of the boundaries, enabling efficient filtering of data based on a given
range of values.
BETWEEN NOT BETWEEN
SELECT SELECT
column1, column1,
column2 column2
FROM FROM
table_name table_name
WHERE WHERE
column1 column1
IN and WILDCARDS
LIKE
The LIKE operator is used with wildcard characters such as (‘%’ and/or ‘_’) to allow for pattern-based searching.
% before % after
SELECT SELECT
column1, column1,
column2 column2
FROM FROM
table_name table_name
WHERE WHERE
column1 column1
LIKE LIKE
“%XXXX”; “XXXX%”;
SELECT SELECT
column1, column1,
column2 column2
FROM FROM
table_name table_name
WHERE WHERE
column1 IS NOT NULL; column1 IS NULL;