One Pager Cheat Sheet
- A database is
a system
used tosave and process data
in an efficient manner, usuallystored in a tabular
format toinsert
and manipulate information. SQL
is a global standardstructured query language
, which is used to perform operations onrelational databases
like inserting, deleting, and updating, and is considered intuitive and easy-to-use.- The
SQL
statementCREATE TABLE
is used to create a new table in a database, specifying a mandatory table_name and the optional columns with their datatypes. - Using the
CREATE TABLE
statement, we can create a new table or derive one from an existing table in an existing database. - We can
create
a new table calledClass
containing "studies" information by passingcolumn names
and their correspondingdata types
to a query. - SQL
DESC
andDESCRIBE
are alias statements used to list information about a table, such as key attributes and data types. DESCRIBE
is a helpfulSQL
statement for seeing information about a table, such as column names, data types and null value presence.- The SELECT statement is used to query a table for specific data, returning a
result-set
of its associated columns and properties. - The
SELECT
statement in SQL is an intuitive way toretrieve columns
from agiven table
. - The statement
SELECT *
will extractall columns
from a table. INSERT
,UPDATE
, andDELETE
are SQL statements used to manipulate values stored in atable
.- To update or delete records from a table in a database, you can use
UPDATE
orDELETE
SQL statements respectively. - The BETWEEN operator is used with the
WHERE
clause to select values within a specified range and is not valid without it. - We can use the
BETWEEN
operator to perform an operation on a specified range, by combining it with theSELECT/ FROM
andWHERE
statements. - The order of operations in the WHERE clause is determined by the order of precedence which consists of relational operators (
>=
,>
,<=
,<
) followed by the OR operator, and finally the equality checks (=
and!=
). - The order of operations within the
WHERE
clause can be enforced with parentheses (()
) to selectively filter data using theSELECT/ FROM
statement. - You can
find students
whose attendance count is greater than 80 in English by using logical operators. - The
WHERE
clause works on individual records, while theHAVING
clause works ongrouped data
and allows us to useaggregate functions
. - We
group
the data and then use theHAVING
clause to apply the condition. - Aggregate functions, such as
AVG()
, return a single value calculated from a set of input values. Aggregate functions
are used to compute and return a single value from multiple values in aSQL
database, such asMIN()
,MAX()
,SUM()
,AVG()
, andCOUNT()
.- The
MIN()
function is used tofind the row with the minimum value
of acolumn
in a query. - The
MAX()
functionis used
to find the maximum value of a column. - The
SUM()
function can be used to find the total amount of values from a column. - The
AVG()
function is used to calculate the mean value of a column. - The
COUNT()
function is used to find the number of rows for a given column, not ignoringnull
values by default. - The
JOIN
clause is used tojoin
data from multiple tables based on their common columns, forming relationships and returning a single result set. - The JOIN clause is used in
SQL
to combine two or more tables based on a mutual column, and can be executed with four types of joins:INNER
,RIGHT OUTER
,LEFT OUTER
, andFULL OUTER
.