Queries - Working with joins Flashcards
(10 cards)
what is natural join in SF?
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)
what are the types of sub queries?
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.
What are scalar vs non scalar subqueries?
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.
What type of sub queries SF supports?
- correlated scalar subqueries in where clause
- uncorrelated scalar subqueries in anyplace a expression can be used.
- EXISTS, ANY / ALL, and IN subqueries in WHERE clauses. These subqueries can be correlated or uncorrelated.
how many rows uncorrelated scalar sub query brings?
1 row
what is a CTE in SF?
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.
Can CTE name match table/view/M view name?
yes but not recommended. If it happens CTE tables precedence.
what is a recursive CTE?
Recursive CTE references itself. It is mainly to process hierarchical data.
what use case is very common for recursive CTE?
Hierarchical data - like managers/employees etc.
what are the most common sections of recursive CTE?
Within the CTE we should have anchor clause union all recursive clause referencing the anchor and having a terminator clause.