0% found this document useful (0 votes)
81 views34 pages

Learn More SOQL Queries.

Uploaded by

subakirudhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views34 pages

Learn More SOQL Queries.

Uploaded by

subakirudhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

‭ .

‬ Q
1 ‭ ueries 1-50:‬‭Basic SOQL queries for standard and custom objects.‬
‭2.‬ ‭Queries 51-100:‬‭SOQL relationship queries (parent-child, child-parent).‬
‭3.‬ ‭Queries 101-150:‬‭SOQL semi-join and anti-join operations.‬

‭Part 1: Basic SOQL Queries for Standard and Custom Objects (1-50)‬

‭ .‬
1
Account‬‭records.‬
‭Question:‬‭Retrieve all‬‭
‭Answer:‬

SELECT Id, Name FROM Account‬


‭ .‬
2
Contact‬‭records where the‬‭
‭Question:‬‭Retrieve all‬‭ LastName‬‭is 'Smith'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE LastName = 'Smith'‬


‭ .‬
3
Opportunities‬‭with an‬‭
‭Question:‬‭Retrieve‬‭ Amount‬‭greater than 1,000,000.‬
‭Answer:‬

SELECT Id, Name, Amount FROM Opportunity WHERE Amount > 1000000‬

‭ .‬
4
Cases‬‭that are currently‬‭
‭Question:‬‭Retrieve‬‭ Closed‬
‭.‬
‭Answer:‬

SELECT Id, CaseNumber, Status FROM Case WHERE Status = 'Closed'‬


‭ .‬
5
Leads‬‭that have been converted.‬
‭Question:‬‭Retrieve‬‭
‭Answer:‬
SELECT Id, FirstName, LastName FROM Lead WHERE IsConverted = TRUE‬

‭ .‬
6
Accounts‬‭ordered by‬‭
‭Question:‬‭Retrieve the first 10‬‭ Name‬
‭.‬
‭Answer:‬

SELECT Id, Name FROM Account ORDER BY Name LIMIT 10‬


‭ .‬
7
Opportunities‬‭that closed in the last 30 days.‬
‭Question:‬‭Retrieve‬‭
‭Answer:‬

SELECT Id, Name, CloseDate FROM Opportunity WHERE CloseDate =‬



LAST_N_DAYS:30‬

‭ .‬
8
Contacts‬‭that belong to‬‭
‭Question:‬‭Retrieve‬‭ Account‬‭'Acme Inc.'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE Account.Name = 'Acme‬



Inc.'‬

‭ .‬
9
Tasks‬‭that are overdue.‬
‭Question:‬‭Retrieve‬‭
‭Answer:‬

SELECT Id, Subject, ActivityDate FROM Task WHERE ActivityDate < TODAY‬

AND Status != 'Completed'‬

‭ 0.‬
1
Opportunities‬‭grouped by‬‭
‭Question:‬‭Retrieve‬‭ StageName‬
‭.‬
‭Answer:‬

SELECT StageName, COUNT(Id) FROM Opportunity GROUP BY StageName‬



‭ 1.‬
1
Accounts‬‭without any‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬
‭.‬
‭Answer:‬

SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM‬

Opportunity)‬

‭ 2.‬
1
Opportunities‬‭where‬‭
‭Question:‬‭Retrieve‬‭ Probability‬‭is greater than or equal to 80%.‬
‭Answer:‬

SELECT Id, Name, Probability FROM Opportunity WHERE Probability >= 80‬

‭ 3.‬
1
Accounts‬‭that have a‬‭
‭Question:‬‭Retrieve the‬‭ BillingState‬‭of 'California'.‬
‭Answer:‬

SELECT Id, Name FROM Account WHERE BillingState = 'California'‬


‭ 4.‬
1
Tasks‬‭that are associated with a particular‬‭
‭Question:‬‭Retrieve all‬‭ Contact‬
‭.‬
‭Answer:‬

SELECT Id, Subject FROM Task WHERE WhoId = '003XXXXXXXXXXXXXXX'‬


‭ 5.‬
1
Contacts‬‭created in the last week.‬
‭Question:‬‭Retrieve all‬‭
‭Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE CreatedDate =‬



LAST_WEEK‬

‭ 6.‬
1
Leads‬‭with‬‭
‭Question:‬‭Retrieve‬‭ LeadSource‬‭set to 'Web'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Lead WHERE LeadSource = 'Web'‬


‭ 7.‬
1
Opportunities‬‭associated with‬‭
‭Question:‬‭Retrieve all‬‭ Account‬‭'Global Media'.‬
‭Answer:‬

SELECT Id, Name FROM Opportunity WHERE Account.Name = 'Global Media'‬


‭ 8.‬
1
Cases‬‭that were created in the last 24 hours.‬
‭Question:‬‭Retrieve‬‭
‭Answer:‬

SELECT Id, CaseNumber, CreatedDate FROM Case WHERE CreatedDate =‬



LAST_24_HOURS‬

‭ 9.‬
1
Opportunities‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ CloseDate‬‭in the next 7 days.‬
‭Answer:‬

SELECT Id, Name, CloseDate FROM Opportunity WHERE CloseDate =‬



NEXT_N_DAYS:7‬

‭ 0.‬
2
Accounts‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ Type‬‭of 'Customer'.‬
‭Answer:‬

SELECT Id, Name, Type FROM Account WHERE Type = 'Customer'‬



‭ 1.‬
2
Cases‬‭that are still open and have a‬‭
‭Question:‬‭Retrieve‬‭ Priority‬‭of 'High'.‬
‭Answer:‬

SELECT Id, CaseNumber, Priority FROM Case WHERE Status != 'Closed' AND‬

Priority = 'High'‬

‭ 2.‬
2
Opportunities‬‭where the‬‭
‭Question:‬‭Retrieve all‬‭ StageName‬‭is 'Closed Won'.‬
‭Answer:‬

SELECT Id, Name FROM Opportunity WHERE StageName = 'Closed Won'‬


‭ 3.‬
2
Accounts‬‭that have not been updated in the last year.‬
‭Question:‬‭Retrieve‬‭
‭Answer:‬

SELECT Id, Name, LastModifiedDate FROM Account WHERE LastModifiedDate‬



< LAST_N_YEARS:1‬

‭ 4.‬
2
Contacts‬‭whose‬‭
‭Question:‬‭Retrieve‬‭ Title‬‭is 'CEO'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE Title = 'CEO'‬


‭ 5.‬
2
Cases‬‭with a‬‭
‭Question:‬‭Retrieve all‬‭ CaseOrigin‬‭of 'Phone'.‬
‭Answer:‬

SELECT Id, CaseNumber, CaseOrigin FROM Case WHERE CaseOrigin = 'Phone'‬



‭ 6.‬
2
Opportunities‬‭created by a specific‬‭
‭Question:‬‭Retrieve‬‭ User‬
‭.‬
‭Answer:‬

SELECT Id, Name FROM Opportunity WHERE CreatedById =‬



'005XXXXXXXXXXXXXXX'‬

‭ 7.‬
2
Contacts‬‭with an‬‭
‭Question:‬‭Retrieve all‬‭ Email‬‭domain of 'example.com'.‬
‭Answer:‬

SELECT Id, FirstName, LastName, Email FROM Contact WHERE Email LIKE‬

'%@example.com'‬

‭ 8.‬
2
Leads‬‭that have a‬‭
‭Question:‬‭Retrieve‬‭ Rating‬‭of 'Hot'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Lead WHERE Rating = 'Hot'‬


‭ 9.‬
2
Opportunities‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ Probability‬‭less than 20%.‬
‭Answer:‬

SELECT Id, Name, Probability FROM Opportunity WHERE Probability < 20‬

‭ 0.‬
3
Accounts‬‭that have a‬‭
‭Question:‬‭Retrieve‬‭ ShippingCountry‬‭of 'USA'.‬
‭Answer:‬

SELECT Id, Name FROM Account WHERE ShippingCountry = 'USA'‬



‭ 1.‬
3
Tasks‬‭that are not completed yet.‬
‭Question:‬‭Retrieve‬‭
‭Answer:‬

SELECT Id, Subject, Status FROM Task WHERE Status != 'Completed'‬


‭ 2.‬
3
Opportunities‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ CloseDate‬‭in the past.‬
‭Answer:‬

SELECT Id, Name, CloseDate FROM Opportunity WHERE CloseDate < TODAY‬

‭ 3.‬
3
Cases‬‭where the‬‭
‭Question:‬‭Retrieve‬‭ Status‬‭is 'New'.‬
‭Answer:‬

SELECT Id, CaseNumber, Status FROM Case WHERE Status = 'New'‬


‭ 4.‬
3
Contacts‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ MailingState‬‭of 'New York'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE MailingState = 'New‬



York'‬

‭ 5.‬
3
Opportunities‬‭that are in the‬‭
‭Question:‬‭Retrieve all‬‭ Proposal/Price Quote‬‭stage.‬
‭Answer:‬

SELECT Id, Name FROM Opportunity WHERE StageName = 'Proposal/Price‬



Quote'‬

‭ 6.‬
3
Accounts‬‭that have an‬‭
‭Question:‬‭Retrieve‬‭ Industry‬‭of 'Technology'.‬
‭Answer:‬

SELECT Id, Name FROM Account WHERE Industry = 'Technology'‬


‭ 7.‬
3
Opportunities‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ CloseDate‬‭within the next 30 days.‬
‭Answer:‬

SELECT Id, Name, CloseDate FROM Opportunity WHERE CloseDate =‬



NEXT_N_DAYS:30‬

‭ 8.‬
3
Leads‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ LeadSource‬‭of 'Referral'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Lead WHERE LeadSource = 'Referral'‬


‭ 9.‬
3
Cases‬‭created today.‬
‭Question:‬‭Retrieve‬‭
‭Answer:‬

SELECT Id, CaseNumber, CreatedDate FROM Case WHERE CreatedDate = TODAY‬


‭ 0.‬
4
Contacts‬‭with a‬‭
‭Question:‬‭Retrieve all‬‭ MailingCountry‬‭of 'Canada'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE MailingCountry =‬



'Canada'‬

‭ 1.‬
4
Opportunities‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ StageName‬‭of 'Prospecting'.‬
‭Answer:‬

SELECT Id, Name FROM Opportunity WHERE StageName = 'Prospecting'‬


‭ 2.‬
4
Accounts‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ Type‬‭of 'Prospect'.‬
‭Answer:‬

SELECT Id, Name, Type FROM Account WHERE Type = 'Prospect'‬


‭ 3.‬
4
Leads‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ Status‬‭of 'Open - Not Contacted'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Lead WHERE Status = 'Open - Not‬

Contacted'‬

‭ 4.‬
4
Opportunities‬‭that are associated with‬‭
‭Question:‬‭Retrieve‬‭ Accounts‬‭in 'California'.‬
‭Answer:‬

SELECT Id, Name FROM Opportunity WHERE Account.BillingState =‬



'California'‬

‭ 5.‬
4
Cases‬‭that are‬‭
‭Question:‬‭Retrieve‬‭ Escalated‬
‭.‬
‭Answer:‬

SELECT Id, CaseNumber, IsEscalated FROM Case WHERE IsEscalated = TRUE‬



‭ 6.‬
4
Opportunities‬‭with a‬‭
‭Question:‬‭Retrieve‬‭ Probability‬‭of 50% or more.‬
‭Answer:‬

SELECT Id, Name, Probability FROM Opportunity WHERE Probability >= 50‬

‭ 7.‬
4
Accounts‬‭that have a‬‭
‭Question:‬‭Retrieve‬‭ BillingCity‬‭of 'New York'.‬
‭Answer:‬

SELECT Id, Name FROM Account WHERE BillingCity = 'New York'‬


‭ 8.‬
4
Contacts‬‭with a‬‭
‭Question:‬‭Retrieve all‬‭ MailingPostalCode‬‭of '10001'.‬
‭Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE MailingPostalCode =‬



'10001'‬

‭ 9.‬
4
Leads‬‭that were created in the last 7 days.‬
‭Question:‬‭Retrieve‬‭
‭Answer:‬

SELECT Id, FirstName, LastName FROM Lead WHERE CreatedDate =‬



LAST_N_DAYS:7‬

‭ 0.‬
5
Opportunities‬‭with an‬‭
‭Question:‬‭Retrieve‬‭ Amount‬‭less than 5,000.‬
‭Answer:‬

SELECT Id, Name, Amount FROM Opportunity WHERE Amount < 5000‬

‭Part 2: SOQL Relationship Queries (51-100)‬


‭ 1.‬
5
Contacts‬‭related to‬‭
‭Question:‬‭Retrieve all‬‭ Account‬‭'Acme Inc.'.‬
‭Answer:‬

SELECT Id, FirstName, LastName, Account.Name FROM Contact WHERE‬



Account.Name = 'Acme Inc.'‬

‭ 2.‬
5
Opportunities‬‭related to‬‭
‭Question:‬‭Retrieve‬‭ Account‬‭'Global Media'.‬
‭Answer:‬

SELECT Id, Name, Account.Name FROM Opportunity WHERE Account.Name =‬



'Global Media'‬

‭ 3.‬
5
Cases‬‭related to‬‭
‭Question:‬‭Retrieve‬‭ Contact‬‭'John Doe'.‬
‭Answer:‬

SELECT Id, CaseNumber, Contact.Name FROM Case WHERE Contact.Name =‬



'John Doe'‬

‭ 4.‬
5
OpportunityLineItems‬‭related to‬‭
‭Question:‬‭Retrieve‬‭ Opportunity‬‭'Opportunity1'.‬
‭Answer:‬

SELECT Id, Opportunity.Name, Product2.Name FROM OpportunityLineItem‬



WHERE Opportunity.Name = 'Opportunity1'‬

‭ 5.‬
5
Opportunities‬‭and their related‬‭
‭Question:‬‭Retrieve‬‭ Accounts‬
‭.‬
‭Answer:‬

SELECT Id, Name, Account.Name FROM Opportunity‬



‭ 6.‬
5
Contacts‬‭along with their‬‭
‭Question:‬‭Retrieve‬‭ Account‬‭information.‬
‭Answer:‬

SELECT Id, FirstName, LastName, Account.Name, Account.Industry FROM‬



Contact‬

‭ 7.‬
5
Accounts‬‭and their related‬‭
‭Question:‬‭Retrieve‬‭ Contacts‬
‭.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts) FROM‬

Account‬

‭ 8.‬
5
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭that closed in the last month.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities WHERE CloseDate =‬

LAST_MONTH) FROM Account‬

‭ 9.‬
5
Contacts‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Cases‬
‭.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, CaseNumber FROM Cases)‬



FROM Contact‬

‭ 0.‬
6
Opportunities‬‭with‬‭
‭Question:‬‭Retrieve‬‭ OpportunityLineItems‬
‭.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Product2.Name, Quantity FROM‬



OpportunityLineItems) FROM Opportunity‬

‭ 1.‬
6
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Contacts‬‭and‬‭
Opportunities‬
‭.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts),‬



(SELECT Id, Name FROM Opportunities) FROM Account‬

‭ 2.‬
6
Opportunities‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Products‬
‭.‬
‭Answer:‬

SELECT Id, Name, (SELECT Product2.Name, Quantity FROM‬



OpportunityLineItems) FROM Opportunity‬

‭ 3.‬
6
Accounts‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Cases‬‭and‬‭
Contacts‬
‭.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, CaseNumber FROM Cases), (SELECT Id,‬

FirstName, LastName FROM Contacts) FROM Account‬

‭ 4.‬
6
Contacts‬‭and their‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭through their related‬‭
Account‬
‭.‬
‭Answer:‬

SELECT Id, FirstName, LastName, Account.Name, (SELECT Id, Name FROM‬



Account.Opportunities) FROM Contact‬

‭ 5.‬
6
Opportunities‬‭and their‬‭
‭Question:‬‭Retrieve‬‭ Account‬‭and‬‭
Contact‬‭details.‬
‭Answer:‬

SELECT Id, Name, Account.Name, (SELECT Id, FirstName, LastName FROM‬



Account.Contacts) FROM Opportunity‬

‭ 6.‬
6
Contacts‬‭along with their‬‭
‭Question:‬‭Retrieve‬‭ Account‬‭and‬‭
Opportunity‬‭information.‬
‭Answer:‬

SELECT Id, FirstName, LastName, Account.Name, (SELECT Id, Name FROM‬



Account.Opportunities) FROM Contact‬

‭ 7.‬
6
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Contacts‬‭where the‬‭
Account‬‭industry is 'Technology'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts) FROM‬

Account WHERE Industry = 'Technology'‬

‭ 8.‬
6
Opportunities‬‭with related‬‭
‭Question:‬‭Retrieve‬‭ Tasks‬
‭.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Subject FROM Tasks) FROM Opportunity‬

‭ 9.‬
6
Contacts‬‭with their related‬‭
‭Question:‬‭Retrieve‬‭ Cases‬‭where‬‭
Case‬‭status is 'Open'.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, CaseNumber FROM Cases‬



WHERE Status = 'Open') FROM Contact‬

‭ 0.‬
7
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭that‬‭have a‬‭
CloseDate‬‭in the last 30‬
‭days.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities WHERE CloseDate =‬

LAST_N_DAYS:30) FROM Account‬

‭ 1.‬
7
Contacts‬‭along with their‬‭
‭Question:‬‭Retrieve‬‭ Account‬‭and‬‭
Case‬‭information.‬
‭Answer:‬

SELECT Id, FirstName, LastName, Account.Name, (SELECT Id, CaseNumber‬



FROM Account.Cases) FROM Contact‬

‭ 2.‬
7
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭and‬‭
Cases‬
‭.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities), (SELECT Id,‬

CaseNumber FROM Cases) FROM Account‬

‭ 3.‬
7
Opportunities‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Account‬‭and‬‭
Contact‬‭details where the‬
‭pportunity‬‭is in 'Prospecting' stage.‬
O
‭Answer:‬

SELECT Id, Name, Account.Name, (SELECT Id, FirstName, LastName FROM‬



Account.Contacts) FROM Opportunity WHERE StageName = 'Prospecting'‬

‭ 4.‬
7
Contacts‬‭and their‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭where the‬‭
Opportunity‬‭stage is‬
‭'Closed Won'.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, Name FROM‬



Account.Opportunities WHERE StageName = 'Closed Won') FROM Contact‬

‭ 5.‬
7
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Contacts‬‭and‬‭
Opportunities‬‭that have a‬
‭robability‬‭of 50% or more.‬
P
‭Answer:‬
SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts),‬

(SELECT Id, Name FROM Opportunities WHERE Probability >= 50) FROM‬

Account‬

‭ 6.‬
7
Opportunities‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Products‬‭where the‬‭
Product‬‭is 'Laptop'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Product2.Name FROM OpportunityLineItems WHERE‬



Product2.Name = 'Laptop') FROM Opportunity‬

‭ 7.‬
7
‭Question:‬‭Retrieve‬‭Contacts‬‭with their‬‭
Opportunities‬‭where the‬‭
Opportunity‬‭amount is‬
‭greater than 10,000.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, Name FROM‬



Account.Opportunities WHERE Amount > 10000) FROM Contact‬

‭ 8.‬
7
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭where‬‭the‬‭
Opportunity‬‭amount is less‬
‭than 5,000.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities WHERE Amount <‬

5000) FROM Account‬

‭ 9.‬
7
Contacts‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Cases‬‭where the‬‭
Case‬‭priority is 'High'.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, CaseNumber FROM Cases‬



WHERE Priority = 'High') FROM Contact‬

‭ 0.‬
8
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Contacts‬‭where the‬‭
Account‬‭type is 'Customer'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts) FROM‬

Account WHERE Type = 'Customer'‬

‭ 1.‬
8
Opportunities‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ OpportunityLineItems‬‭where the‬
‭uantity‬‭is greater than 5.‬
Q
‭Answer:‬

SELECT Id, Name, (SELECT Product2.Name, Quantity FROM‬



OpportunityLineItems WHERE Quantity > 5) FROM Opportunity‬

‭ 2.‬
8
‭Question:‬‭Retrieve‬‭ Accounts‬‭with‬‭
Opportunities‬‭where‬‭the‬‭
Opportunity‬‭is in‬
‭'Qualification' stage.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities WHERE StageName =‬

'Qualification') FROM Account‬

‭ 3.‬
8
Contacts‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Cases‬‭where the‬‭
Case‬‭is‬‭
Closed‬
‭.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, CaseNumber FROM Cases‬



WHERE Status = 'Closed') FROM Contact‬

‭ 4.‬
8
Opportunities‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ OpportunityLineItems‬‭where the‬
‭otalPrice‬‭is greater than 10,000.‬
T
‭Answer:‬
SELECT Id, Name, (SELECT Product2.Name, TotalPrice FROM‬

OpportunityLineItems WHERE TotalPrice > 10000) FROM Opportunity‬

‭ 5.‬
8
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭that‬‭have a‬‭
CloseDate‬‭in the next 30‬
‭days.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities WHERE CloseDate =‬

NEXT_N_DAYS:30) FROM Account‬

‭ 6.‬
8
‭Question:‬‭Retrieve‬‭ Contacts‬‭with their‬‭
Opportunities‬‭where the‬‭
Opportunity‬‭is in‬
‭'Negotiation' stage.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, Name FROM‬



Account.Opportunities WHERE StageName = 'Negotiation/Review') FROM‬

Contact‬

‭ 7.‬
8
Opportunities‬‭with‬‭
‭Question:‬‭Retrieve‬‭ OpportunityLineItems‬‭where the‬‭
Discount‬‭is‬
‭greater than 20%.‬
‭Answer:‬

SELECT Id, Name, (SELECT Product2.Name, Discount FROM‬



OpportunityLineItems WHERE Discount > 0.2) FROM Opportunity‬

‭ 8.‬
8
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭where‬‭the‬‭
Opportunity‬‭stage is‬
‭'Closed Lost'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities WHERE StageName =‬

'Closed Lost') FROM Account‬

‭ 9.‬
8
Contacts‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Cases‬‭where the‬‭
Case‬‭type is 'Problem'.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, CaseNumber FROM Cases‬



WHERE Type = 'Problem') FROM Contact‬

‭ 0.‬
9
Opportunities‬‭with‬‭
‭Question:‬‭Retrieve‬‭ OpportunityLineItems‬‭where the‬‭
Quantity‬‭is‬
‭less than 10.‬
‭Answer:‬

SELECT Id, Name, (SELECT Product2.Name, Quantity FROM‬



OpportunityLineItems WHERE Quantity < 10) FROM Opportunity‬

‭ 1.‬
9
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Contacts‬‭where the‬‭
Contact‬‭is in 'California'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts WHERE‬

MailingState = 'California') FROM Account‬

‭ 2.‬
9
Contacts‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭where the‬‭
Opportunity‬‭amount is‬
‭between 5,000 and 10,000.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, Name FROM‬



Account.Opportunities WHERE Amount >= 5000 AND Amount <= 10000) FROM‬

Contact‬

‭ 3.‬
9
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭where‬‭the‬‭
Opportunity‬‭stage is‬
'‭Proposal/Price Quote'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities WHERE StageName =‬

'Proposal/Price Quote') FROM Account‬

‭ 4.‬
9
Contacts‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Cases‬‭where the‬‭
Case‬‭is‬‭
Escalated‬
‭.‬
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, CaseNumber FROM Cases‬



WHERE IsEscalated = TRUE) FROM Contact‬

‭ 5.‬
9
‭Question:‬‭Retrieve‬‭ Opportunities‬‭with‬‭
OpportunityLineItems‬‭where the‬‭
Product‬
‭name is 'Software'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Product2.Name FROM OpportunityLineItems WHERE‬



Product2.Name = 'Software') FROM Opportunity‬

‭ 6.‬
9
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Contacts‬‭where the‬‭
Account‬‭type is 'Partner'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts) FROM‬

Account WHERE Type = 'Partner'‬

‭ 7.‬
9
Opportunities‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Products‬‭where the‬‭
Quantity‬‭is greater than 20.‬
‭Answer:‬

SELECT Id, Name, (SELECT Product2.Name, Quantity FROM‬



OpportunityLineItems WHERE Quantity > 20) FROM Opportunity‬

‭ 8.‬
9
Accounts‬‭with‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭where‬‭the‬‭
Opportunity‬‭stage is‬
‭'Closed Won'.‬
‭Answer:‬

SELECT Id, Name, (SELECT Id, Name FROM Opportunities WHERE StageName =‬

'Closed Won') FROM Account‬

‭ 9.‬
9
Contacts‬‭with their‬‭
‭Question:‬‭Retrieve‬‭ Opportunities‬‭where the‬‭
Opportunity‬‭has a‬
‭robability‬‭of 75% or more.‬
P
‭Answer:‬

SELECT Id, FirstName, LastName, (SELECT Id, Name FROM‬



Account.Opportunities WHERE Probability >= 75) FROM Contact‬

‭ 00.‬
1
‭Question:‬‭Retrieve‬‭ Opportunities‬‭with‬‭
OpportunityLineItems‬‭where the‬‭
TotalPrice‬
‭is less than 5,000.‬
‭Answer:‬

SELECT Id, Name, (SELECT Product2.Name, TotalPrice FROM‬



OpportunityLineItems WHERE TotalPrice < 5000) FROM Opportunity‬

SOQL queries numbered 101-150, focusing on semi-join and anti-join‬



operations:‬

101.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have at least one‬‭
Opportunity‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Opportunity)‬

102.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
that are related to an‬‭
Account‬‭
with the‬
type 'Customer'.‬

Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE AccountId IN (SELECT‬



Id FROM Account WHERE Type = 'Customer')‬

103.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are associated‬‭
with an‬‭
Account‬
from the 'Technology' industry.‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE AccountId IN (SELECT Id FROM‬



Account WHERE Industry = 'Technology')‬

104.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are related to‬‭
Contacts‬‭
who have an open‬
Opportunity‬
‭ .‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE ContactId IN (SELECT Id FROM‬



Contact WHERE AccountId IN (SELECT AccountId FROM Opportunity WHERE‬

IsClosed = FALSE))‬

105.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that do not have any‬‭
Opportunities‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM‬

Opportunity)‬

106.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who do not have any associated‬‭
Cases‬
.‬

Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE Id NOT IN (SELECT‬



ContactId FROM Case)‬

107.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that do not have‬‭
any‬
OpportunityLineItems‬
‭ .‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE Id NOT IN (SELECT OpportunityId‬



FROM OpportunityLineItem)‬

108.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that do not have any associated‬‭
Contacts‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM‬

Contact)‬

109.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who do not have any associated‬
Opportunities‬
‭ .‬

Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE AccountId NOT IN‬

(SELECT AccountId FROM Opportunity)‬

110.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are associated‬‭
with‬‭
Contacts‬‭
in‬
the 'Manufacturing' industry.‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE AccountId IN (SELECT AccountId‬



FROM Contact WHERE Account.Industry = 'Manufacturing')‬

111.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that do not have any associated‬‭
Tasks‬
.‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE Id NOT IN (SELECT WhatId FROM‬

Task WHERE What.Type = 'Case')‬

112.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have related‬‭
Opportunities‬‭
in the‬
'Closed Won' stage.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Opportunity WHERE StageName = 'Closed Won')‬

113.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
that are not related to‬‭
Accounts‬‭
in the‬
'Banking' industry.‬

Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE AccountId NOT IN‬

(SELECT Id FROM Account WHERE Industry = 'Banking')‬

114.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that have associated‬
OpportunityLineItems‬‭
‭ with a‬‭
TotalPrice‬‭
greater than 5,000.‬
Answer:‬

SELECT Id, Name FROM Opportunity WHERE Id IN (SELECT OpportunityId‬

FROM OpportunityLineItem WHERE TotalPrice > 5000)‬

115.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are not associated with‬‭
Contacts‬‭
from‬
Accounts‬‭
‭ in the 'Retail' industry.‬
Answer:‬

SELECT Id, CaseNumber FROM Case WHERE ContactId NOT IN (SELECT Id FROM‬

Contact WHERE Account.Industry = 'Retail')‬

116.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have no associated‬‭
Cases‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM‬

Case)‬

117.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
that are associated with‬‭
Opportunities‬‭
in‬
the 'Prospecting' stage.‬

Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE AccountId IN (SELECT‬



AccountId FROM Opportunity WHERE StageName = 'Prospecting')‬

118.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are not associated‬‭
with‬‭
Contacts‬
from the 'Financial Services' industry.‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE AccountId NOT IN (SELECT‬

AccountId FROM Contact WHERE Account.Industry = 'Financial Services')‬

119.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are related to‬‭
Contacts‬‭
from‬‭
Accounts‬‭
in‬
the 'Healthcare' industry.‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE ContactId IN (SELECT Id FROM‬



Contact WHERE Account.Industry = 'Healthcare')‬

120.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have associated‬‭
Contacts‬‭
but no‬
associated‬‭
‭ Opportunities‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Contact) AND Id NOT IN (SELECT AccountId FROM Opportunity)‬

121.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are associated‬‭
with‬‭
Accounts‬
having no associated‬‭
‭ Contacts‬
.‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE AccountId NOT IN (SELECT‬



AccountId FROM Contact)‬

122.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are not associated with‬‭
Opportunities‬
.‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE Id NOT IN (SELECT WhatId FROM‬

Opportunity WHERE What.Type = 'Case')‬

123.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that are associated with‬‭
Opportunities‬‭
in‬
the 'Qualification' stage but have no associated‬‭
‭ Cases‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Opportunity WHERE StageName = 'Qualification') AND Id NOT IN (SELECT‬

AccountId FROM Case)‬

124.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who have no associated‬‭
Cases‬‭
but are‬
related to‬‭
‭ Opportunities‬‭
in the 'Closed Won' stage.‬
Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE Id NOT IN (SELECT‬



ContactId FROM Case) AND AccountId IN (SELECT AccountId FROM‬

Opportunity WHERE StageName = 'Closed Won')‬

125.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that have no associated‬
OpportunityLineItems‬‭
‭ and are not in the 'Closed Lost' stage.‬
Answer:‬

SELECT Id, Name FROM Opportunity WHERE Id NOT IN (SELECT OpportunityId‬



FROM OpportunityLineItem) AND StageName != 'Closed Lost'‬

126.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have no associated‬‭
Opportunities‬‭
and‬
no associated‬‭
‭ Contacts‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM‬

Opportunity) AND Id NOT IN (SELECT AccountId FROM Contact)‬

127.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who are not associated with any‬
Opportunities‬‭
‭ and are from‬‭
Accounts‬‭
in the 'Nonprofit' industry.‬
Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE AccountId IN (SELECT‬



Id FROM Account WHERE Industry = 'Nonprofit') AND AccountId NOT IN‬

(SELECT AccountId FROM Opportunity)‬

128.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are associated‬‭
with‬‭
Accounts‬
having‬‭
‭ Cases‬‭
in the 'Escalated' status.‬
Answer:‬

SELECT Id, Name FROM Opportunity WHERE AccountId IN (SELECT AccountId‬



FROM Case WHERE IsEscalated = TRUE)‬

129.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are related to‬‭
Opportunities‬‭
in the‬
'Proposal/Price Quote' stage.‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE Id IN (SELECT WhatId FROM‬



Opportunity WHERE StageName = 'Proposal/Price Quote' AND What.Type =‬

'Case')‬

130.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have no associated‬‭
Contacts‬‭
and no‬
associated‬‭
‭ Opportunities‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM‬

Contact) AND Id NOT IN (SELECT AccountId FROM Opportunity)‬

131.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are associated‬‭
with‬‭
Contacts‬‭
who‬
have no associated‬‭
‭ Cases‬
.‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE AccountId IN (SELECT AccountId‬



FROM Contact WHERE Id NOT IN (SELECT ContactId FROM Case))‬

132.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are associated with‬‭
Opportunities‬‭
in the‬
'Closed Won' stage.‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE Id IN (SELECT WhatId FROM‬



Opportunity WHERE StageName = 'Closed Won' AND What.Type = 'Case')‬

133.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have associated‬‭
Opportunities‬‭
in the‬
'Closed Lost' stage but have no associated‬‭
‭ Cases‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Opportunity WHERE StageName = 'Closed Lost') AND Id NOT IN (SELECT‬

AccountId FROM Case)‬

134.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who have no associated‬‭
Opportunities‬‭
and‬
are related to‬‭
‭ Accounts‬‭
in the 'Energy' industry.‬
Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE AccountId NOT IN‬

(SELECT Id FROM Account WHERE Industry = 'Energy') AND AccountId NOT‬

IN (SELECT AccountId FROM Opportunity)‬

135.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that have no associated‬‭
Cases‬‭
and are‬
related to‬‭
‭ Accounts‬‭
in the 'Agriculture' industry.‬
Answer:‬

SELECT Id, Name FROM Opportunity WHERE Id NOT IN (SELECT WhatId FROM‬

Case) AND AccountId IN (SELECT Id FROM Account WHERE Industry =‬

'Agriculture')‬

136.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are associated with‬‭
Opportunities‬‭
in the‬
'Needs Analysis' stage.‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE Id IN (SELECT WhatId FROM‬



Opportunity WHERE StageName = 'Needs Analysis' AND What.Type = 'Case')‬

137.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have associated‬‭
Contacts‬‭
who have no‬
associated‬‭
‭ Cases‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Contact WHERE Id NOT IN (SELECT ContactId FROM Case))‬

138.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who are not related to‬‭
any‬‭
Opportunities‬
in the 'Qualification' stage.‬

Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE AccountId NOT IN‬

(SELECT AccountId FROM Opportunity WHERE StageName = 'Qualification')‬

139.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are associated‬‭
with‬‭
Cases‬‭
in the‬
'New' status.‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE Id IN (SELECT WhatId FROM Case‬

WHERE Status = 'New' AND What.Type = 'Opportunity')‬

140.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that have associated‬‭
Opportunities‬‭
but no‬
associated‬‭
‭ Cases‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Opportunity) AND Id NOT IN (SELECT AccountId FROM Case)‬

141.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who have no associated‬‭
Cases‬‭
but are‬
related to‬‭
‭ Accounts‬‭
with associated‬‭
Opportunities‬
.‬

Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE Id NOT IN (SELECT‬



ContactId FROM Case) AND AccountId IN (SELECT AccountId FROM‬

Opportunity)‬

142.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are not associated‬‭
with any‬
Cases‬‭
‭ but are in the 'Prospecting' stage.‬
Answer:‬

SELECT Id, Name FROM Opportunity WHERE Id NOT IN (SELECT WhatId FROM‬

Case) AND StageName = 'Prospecting'‬

143.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are related to‬‭
Accounts‬‭
with no‬
associated‬‭
‭ Opportunities‬
.‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE AccountId IN (SELECT Id FROM‬



Account WHERE Id NOT IN (SELECT AccountId FROM Opportunity))‬

144.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who are not associated‬‭
with any‬
Opportunities‬‭
‭ in the 'Proposal/Price Quote' stage.‬
Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE AccountId NOT IN‬

(SELECT AccountId FROM Opportunity WHERE StageName = 'Proposal/Price‬

Quote')‬

145.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that have no associated‬
OpportunityLineItems‬‭
‭ but are related to‬‭
Accounts‬‭
with‬‭
associated‬
Cases‬
‭ .‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE Id NOT IN (SELECT OpportunityId‬



FROM OpportunityLineItem) AND AccountId IN (SELECT AccountId FROM‬

Case)‬

146.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that are associated with‬‭
Opportunities‬‭
in‬
the 'Perception Analysis' stage but have no associated‬‭
‭ Contacts‬
.‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Opportunity WHERE StageName = 'Perception Analysis') AND Id NOT IN‬

(SELECT AccountId FROM Contact)‬

147.‬

Question:‬‭
‭ Retrieve‬‭
Cases‬‭
that are related to‬‭
Accounts‬‭
with no‬
associated‬‭
‭ Contacts‬
.‬

Answer:‬

SELECT Id, CaseNumber FROM Case WHERE AccountId IN (SELECT Id FROM‬



Account WHERE Id NOT IN (SELECT AccountId FROM Contact))‬

148.‬

Question:‬‭
‭ Retrieve‬‭
Contacts‬‭
who are not associated‬‭
with any‬‭
Cases‬‭
in‬
the 'Working' status.‬

Answer:‬

SELECT Id, FirstName, LastName FROM Contact WHERE Id NOT IN (SELECT‬



ContactId FROM Case WHERE Status = 'Working')‬

149.‬

Question:‬‭
‭ Retrieve‬‭
Opportunities‬‭
that are related‬‭
to‬‭
Contacts‬‭
from‬
Accounts‬‭
‭ with no associated‬‭
Cases‬
.‬

Answer:‬

SELECT Id, Name FROM Opportunity WHERE AccountId IN (SELECT AccountId‬



FROM Contact WHERE AccountId NOT IN (SELECT AccountId FROM Case))‬

150.‬

Question:‬‭
‭ Retrieve‬‭
Accounts‬‭
that are associated with‬‭
Opportunities‬‭
in‬
the 'Closed Won' stage and have associated‬‭
‭ Contacts‬‭
but no associated‬
Cases‬
‭ .‬

Answer:‬

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM‬



Opportunity WHERE StageName = 'Closed Won') AND Id IN (SELECT‬

AccountId FROM Contact) AND Id NOT IN (SELECT AccountId FROM Case)‬

You might also like