WHERE
WHERE keeps only the records that match its conditions.
FROM dealsSHOW count, valueWHERE stage IN ("Proposal", "Negotiation") AND owner = meSyntax
Section titled “Syntax”WHERE <condition> [AND | OR <condition> ...]AND is applied before OR. Use parentheses to group conditions, and NOT (…) to turn a group around:
WHERE (source = "Website" OR source = "Referral") AND NOT (stage = "Lost")Conditions
Section titled “Conditions”| Condition | Example |
|---|---|
| Equal, not equal | stage = "Won", stage != "Lost" |
| One of a list | stage IN ("Proposal", "Won"), stage NOT IN ("Lost") |
| Text | name CONTAINS "renewal", STARTS WITH, ENDS WITH, and their NOT versions |
| Numbers | amount > 1000, >=, <, <=, amount BETWEEN 100 AND 500, NOT BETWEEN |
| Dates | close_date >= -30d, created_at = last_month, won_at < startOfYear(0y) |
| Empty or not | close_date IS NULL, close_date IS NOT NULL |
| Yes / no | budget_confirmed IS TRUE, IS FALSE, IS NOT TRUE |
| People | owner = me, owner = "Sam Seller" |
Options (stages, sources, owners…) are written by name, in double quotes. A date range name means its whole range: created_at = last_month matches every day of last month.
Related fields
Section titled “Related fields”Filter on a linked object’s field with its name and a dot:
FROM dealsSHOW countWHERE accounts.industry = "Software" AND contacts.source = "Website"A related field follows every linked record: contacts.source = "Website" keeps a deal when any of its contacts came from the website, including contacts linked to it without being its main contact. To use only the deal’s own contact, filter on lead_source:
FROM dealsSHOW countWHERE stage = "Closed Paid" AND lead_source = "Marketing Generated"GROUP BY monthON won_atWHERE or HAVING
Section titled “WHERE or HAVING”WHERE filters records before they are counted. To filter on a number you show, such as “owners with more than 5 deals”, use HAVING. Functions like sum(amount) can’t be used in WHERE for the same reason.