AND Operator
Not Started

AND as useful as all that is, we can really start to pile it on when we introduce our first logical operator AND.

When we use the WHERE clause to filter results, a single condition may not be sufficient for our needs. By using the AND logical operator, we can combine multiple conditions that all need to be true for a record to be included in the results. For example, consider a scenario where we want to find Opportunities that are both high-value and currently in the negotiation stage. Here's how we can do that:

SELECT Name, Amount, StageName FROM Opportunity WHERE Amount > 100000 AND StageName = 'Negotiation/Review'

NameAmountStageName
United Oil Office Portable Generators125000Negotiation/Review
United Oil Installations270000Negotiation/Review



Suppose we want to filter Opportunities to find those that are not new customers, have a probability of winning higher than 50%, and are not yet closed. We would use the AND logical operator to ensure all these conditions are met simultaneously. Here’s how that query might look:

SELECT Name, Type, Probability, IsClosed FROM Opportunity WHERE Type != 'New Customer' AND Probability > 50 AND IsClosed = false

NameTypeProbabilityIsClosed
United Oil Office Portable GeneratorsExisting Customer - Upgrade90FALSE
Grand Hotels Kitchen GeneratorExisting Customer - Upgrade60FALSE
United Oil Refinery GeneratorsExisting Customer - Upgrade75FALSE
............



Lastly, while tempting, we don't necessarily need to show these columns in the SELECT output for which we have specified the condition for. We always know what the value will be in some cases.

SELECT Name, ExpectedRevenue FROM Opportunity WHERE StageName = 'Negotiation/Review' AND Type = 'Existing Customer - Upgrade' AND ExpectedRevenue > 100000

NameExpectedRevenue
United Oil Office Portable Generators112500
United Oil Installations243000



Challenge

Write a query to retrieve the Name, Lead Source, Stage Name, and Closed fields of all Opportunities that come from an "External Referral" lead source and are NOT closed.