0% found this document useful (0 votes)
3 views

Querying-commands_Reference-Card_Final-3783

Uploaded by

younss elaoumari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Querying-commands_Reference-Card_Final-3783

Uploaded by

younss elaoumari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Reference card

Querying commands

Data Query Language


Data Query Language �DQL� allows us to communicate with databases, facilitating precise extraction and manipulation of data.

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.

SELECT ALL SELECT columns


SELECT SELECT
* column1,
FROM column2,
column3
table_name
FROM
LIMIT
table_name
100;
LIMIT
100;

SELECT DISTINCT SELECT WHERE


SELECT DISTINCT eliminates rows where data are duplicated. Like The WHERE clause is used to filter records. It is used to extract only
SELECT, we can check if data in specific column(s) or all columns those records that fulfil a specified condition.
are duplicated, and remove them.
SELECT
SELECT DISTINCT column1,
column1, column2,
column2, column3
column3
FROM
FROM table_name,
table_name,
WHERE
column = value;

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.

Greater than Less than


SELECT SELECT
* *
FROM FROM
table_name table_name

LIMIT LIMIT
column1 > value; column1 < value;

Equal to Less than to


Not equal
SELECT SELECT
* *
FROM FROM
table_name table_name

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

BETWEEN lower_value AND NOT BETWEEN lower_value AND


upper_value; upper_value;

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%”;

IN NOT NULL/IS NULL


IS
A field with a NULL value is a field with no value. The IS NULL statement will select values in a column that contains NULL values. The IS NOT
NULL statement will select values with no nulls in them.
Select values with IS NOT NULL Select values with IS NULL

SELECT SELECT
column1, column1,
column2 column2

FROM FROM
table_name table_name

WHERE WHERE
column1 IS NOT NULL; column1 IS NULL;

You might also like