Database Basics Flashcards
How are queries executed in the REST API?
The “Query” parameter, with a query string
How are queries executed in the SOAP API?
using the query() method
SOQL is used when you know which objects the data resides in and you want to:
Retrieve data from a single object or multiple objects that are related.
Count the number of records that meet a specified criteria.
Sort results as part of the query.
Retrieve data from number, date, or checkbox fields.
What is a SOQL semi-join?
a subquery on another object in an IN clause to restrict the records returned
What is a SOQL anti-join?
A subquery on another object in a NOT IN clause to restrict the records returned.
Explain parent-to-child semi-join.
A parent to child semi-join is when a parent filters for specific child records in the where clause.
ex: selecting opportunities related to an account based on Stage.
select id, name from account where id in (select accountid from opportunity where stagename= ‘closed lost’)
Explain parent-to-child anti-join.
A parent-to-child anti-join is when a parent filters for child records excluded from the where clause.
ex: selecting opportunities related to an account that don’t meet criteria.
select id, name from account where id not in (select accountid from opportunity where stagename = ‘closed lost’)
Explain child-to-child semi-join.
A c2c semi-join is when a result set is filtered by a reference fields of two child objects.
ex: retrieving opportunities for contacts who have a source of ‘web’.
select id from opportunity where accountid in (select accountid from contact where leadsource=’Web’)
Explain child-to-child anti-join.
A c2c semi-join is when a result set is filtered by the exclusion of reference fields of two child objects.
ex: retrieving opportunities for contacts who don’t have a source of ‘web’.
select id from opportunity where accountid not in (select accountid from contact where leadsource=’Web’)
True or false:
Semi-joins & Anti joins can evaluate relationship queries in a SELECT clause.
True
True/False:
Semi-joins/anti-joins can be combined in a single query.
True
What are the 2 basic limits of semi & anti joins?
No more than two IN or NOT IN clauses.
You cannot use NOT with a semi or anti-join
What are the restrictions of the main WHERE clause of a semi or anti join query?
The left operand must query a single ID (PK) or reference (FK).
The left operand can’t use relationships (ex: Account.id).
True/false
A subquery must query a field referencing the same object type as the main query
true
True/false
Standard SOQL limits apply to the number of records matched in a subquery .
False
True/False.
A query that has a subquery is subject to the standard SOQL limits on the main query.
true
True/False.
The selected column in a subquery must be a foreign key field.
true
True/False.
The selected column in a subquery can traverse relationships.
false
True/False.
You can query on the same object in a subquery as a main query.
false
True/False.
You cannot nest a semi or anti join statement in another semi or anti join statement.
True
True/False.
You can use semi/anti-joins in a subquery WHERE clase.
false
True/False.
Subqueries can be used with the OR clause
false
What four clauses are not supported in subqueries?
Count
For Update
Order By
Limit
Which objects are not supported in subqueries?
ActivityHistory Attachments Event EventAttendee Note OpenActivity Tags (AccountTag, ContactTag, etc.) Task