Queries - Working with joins Flashcards

1
Q

what is natural join in SF?

A

this is like a new concept
when you mention table a natural join table b
- all common columns using column names are joined
(more like a inner join but without explicitly mentioning column names on join condition)

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

what are the types of sub queries?

A

correlated and uncorrelated.
correlated means - it references a column from outside of the subquery.
uncorrelated - it is independent and doesn’t reference a column from outside of the sub query.

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

What are scalar vs non scalar subqueries?

A

scalar - returns 1 row/1 column only
non scalar - returns multiple rows/multiple column values.

If no rows qualify, scalar returns NULL
If no rows qualify, non scalar returns Zeroes and not null like scalar.

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

What type of sub queries SF supports?

A
  1. correlated scalar subqueries in where clause
  2. uncorrelated scalar subqueries in anyplace a expression can be used.
  3. EXISTS, ANY / ALL, and IN subqueries in WHERE clauses. These subqueries can be correlated or uncorrelated.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how many rows uncorrelated scalar sub query brings?

A

1 row

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

what is a CTE in SF?

A
CTE stands for common table expressions
It is nothing but a named sub query. 
It is defined using with function. 
with cte_name(col1, col2) as 
(
)
It is more like a temporary view.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can CTE name match table/view/M view name?

A

yes but not recommended. If it happens CTE tables precedence.

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

what is a recursive CTE?

A

Recursive CTE references itself. It is mainly to process hierarchical data.

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

what use case is very common for recursive CTE?

A

Hierarchical data - like managers/employees etc.

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

what are the most common sections of recursive CTE?

A
Within the CTE
we should have anchor clause
union all
recursive clause referencing the anchor
and having a terminator clause.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly