# WHERE

> Count only the records that match: comparisons, lists, text, numbers, dates, empty values, and groups of conditions.

`WHERE` keeps only the records that match its conditions.

```sql
FROM deals
SHOW count, value
WHERE stage IN ("Proposal", "Negotiation") AND owner = me
```

## Syntax

```sql
WHERE <condition> [AND | OR <condition> ...]
```

`AND` is applied before `OR`. Use parentheses to group conditions, and `NOT (…)` to turn a group around:

```sql
WHERE (source = "Website" OR source = "Referral") AND NOT (stage = "Lost")
```

## 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

Filter on a linked object's field with its name and a dot:

```sql
FROM deals
SHOW count
WHERE accounts.industry = "Software" AND contacts.source = "Website"
```

## 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](https://workstation.repzo.com/docs/analytics/repzoql/having). Functions like `sum(amount)` can't be used in `WHERE` for the same reason.

## Related pages

- [HAVING](https://workstation.repzo.com/docs/analytics/repzoql/having)
- [SINCE, UNTIL, DURING](https://workstation.repzo.com/docs/analytics/repzoql/since-until-during)
- [Syntax overview](https://workstation.repzo.com/docs/analytics/repzoql/syntax)
