SQL Flashcards

1
Q

Name the types of SQL operation

A

CRUD
Joins
inner, outer (left/right, full), cross, self
Aggregate functions
count, sum,avg,max, min, group by
subqueries
CTEs (common table expressions)
Set Operations
Union, Union all, Intersect, Except (or minus)
Window Functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are CRUD statements?

A

The 4 most basic SQL operations
create/Insert
Read/select
Update
delete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the aggregate functions?

A

COUNT, SUM, AVG, MAX, MIN, GROUP BY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are set operations?

A

Union, Union all, Intersect, Except (or minus)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are windows functions?

A

In SQL, a window function or analytic function[1] is a function which uses values from one or multiple rows to return a value for each row. (This contrasts with an aggregate function, which returns a single value for multiple rows.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are subqueries?

A

A subquery is a SQL query nested inside a larger query

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are CTEs?

A

A common table expression, or CTE, (in SQL) is a temporary named result set, derived from a simple query and defined within the execution scope of a SELECT, INSERT, UPDATE, or DELETE statement.

CTEs can be thought of as alternatives to derived tables (subquery), views, and inline user-defined functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is an (INNER) join?

A

Returns records that have matching values in both tables

SELECT *
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is an LEFT (OUTER) JOIN

A

Returns all records from the left table, and the matched records from the right table

SELECT *
FROM left table
LEFT JOIN right table
ON left table common column
=
right table common column
;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is a RIGHT (OUTER) JOIN

A

Returns all records from the right table, and the matched records from the left table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is a FULL (OUTER) JOIN

A

Returns all records when there is a match in either left or right table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what are join operations syntax?

A

SELECT
FROM table
JOIN table
ON common col

SELECT *
FROM TABLE1
INNER, LEFT, RIGHT, FULL JOIN TABLE2
ON TAB1.col = TAB2.col

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is a CROSS join?

A

The CROSS JOIN keyword matches ALL records from the “left” table with EACH record from the “right” table.

That means that all records from the “right” table will be returned for each record in the “left” table.

SELECT testproduct_id, product_name, category_name
FROM testproducts
CROSS JOIN categories;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is a SELF join?

A

A self join is a regular join, but the table is joined with itself.

There is NO SELF expression
SELECT column_name(s)
FROM table1 T1, table1 T2
WHERE condition;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is the UNION operator?

A

The UNION operator is used to combine the result-set of two or more SELECT statements.

Every SELECT statement within UNION must have the same number of columns
The columns must also have similar data types
The columns in every SELECT statement must also be in the same order

The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
A