SQL_1 Flashcards
(52 cards)
DELETE command
will delete everything unless given a where condition, can use the rollback command to undo deletions.
TRUNCATE command
deletes all rows but leaves table structure in place, cannot be undone with rollback command
DROP command
drops the entire table structure along with all rows/contents, cannot be undone with rollback command
PRIMARY KEY
constraint can be used to uniquely identify the row.
UNIQUE
columns have a different value for every row.
NOT NULL
columns must have a value.
DEFAULT
assigns a default value for the column when no value is specified.
INSERT INTO
statement is used to add a new record (row) to a table.
UPDATE
statement is used to edit records (rows) in a table. It includes a SET clause that indicates the column to edit and a WHERE clause for specifying the record(s).
% Wildcard
The % wildcard can be used in a LIKE operator pattern to match zero or more unspecified character(s).
_ Wildcard
The _ wildcard can be used in a LIKE operator pattern to match any single unspecified character.
HAVING
The HAVING clause is used to further filter the result set groups provided by the GROUP BY clause. HAVING is often used with aggregate functions to filter the result set groups based on an aggregate property.
ROUND()
he ROUND() function will round a number value to a specified number of places. It takes two arguments: a number, and a number of decimal places. It can be combined with other aggregate functions, as shown in the given query.
Outer Join
An outer join will combine rows from different tables even if the join condition is not met. In a LEFT JOIN, every row in the left table is returned in the result set, and if the join condition is not met, then NULL values are used to fill in the columns from the right table. Left, right, and full joins are all outer joins.
Cross Join
The CROSS JOIN clause is used to combine each row from one table with each row from another in the result set. This JOIN is helpful for creating all possible combinations for the records (rows) in two tables.
Inner Join
The JOIN clause allows for the return of results from more than one table by joining them together with other results based on common column values specified using an ON clause. INNER JOIN is the default JOIN and it will only return results matching the condition specified by ON.
Left join
An outer join that returns all rows from the left table, and the matched rows from the right table
Right join
An outer join that returns all rows from the right table, and the matched rows from the left table
Window Function
Similar to an aggregate function, a window function calculates on a set of rows. However, a window function does not cause rows to become grouped into a single output row.
PARTITION BY
the PARTITION BY clause is a subclause of the OVER clause. The PARTITION BY clause divides a query’s result set into partitions. The window function is operated on each partition separately and recalculate for each partition.
UNION vs JOIN
The UNION operator combines result sets of two or more SELECT statements into a single result set (no duplicates). A JOIN similarly combines tables but does so using common values using ON statements, where as the union operator just adds the select statements together.
UNION ALL
A UNION statement that includes all data from both SELECT statements including duplicates.
CTE / WITH Clause
A Common Table Expression is a named temporary result set. You create a CTE using a WITH query, then reference it within a SELECT, INSERT, UPDATE, or DELETE statement. If you use a CTE, you don’t need to create and drop a table. You can simply reference the temporary result set created by the WITH query
INTERSECT Statement
The SQL INTERSECT clause/operator is used to combine two SELECT statements, but returns rows only from the first SELECT statement that are identical to a row in the second SELECT statement. This means INTERSECT returns only common rows returned by the two SELECT statements.
Just as with the UNION operator, the same rules apply when using the INTERSECT operator. MySQL does not support the INTERSECT operator.