Basic Formatting Rules
- Must be a SELECT Query - goal is to select the record IDs of the people you want to be on the list. You must SELECT the ID field of a Contact, Target, or Lead.
- JOIN statements are allowed after the FROM statement and before the WHERE statement (ex. you want to join the contacts_cstm table to get to custom fields)
- The WHERE statement must be the last thing in your query. ORDER BY, LIMIT, HAVING, GROUP BY are not allowed.
Do not add ‘deleted’ checks to your sql query. We will make sure only non-deleted Contacts/Targets/Leads are added to your lists.
You cannot use the following SQL Keywords in your queries:
- GROUP BY (we will make sure no duplicates are added)
- ORDER BY
- Only targets whose last name is Smith and title is CEO or COO
WHERE prospects.last_name = ‘Smith’ AND (prospects.title = ‘CEO’ OR prospects.title = ‘COO’)
- Only leads where age is less than 8 (custom field)
INNER JOIN leads_cstm ON leads.id=leads_cstm.id_c
WHERE leads_cstm.age_c < 8
- Only contacts where Account Industry is Oil and Gas (related fields)
INNER JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id
INNER JOIN accounts ON accounts_contacts.account_id=accounts.id
WHERE accounts.industry = ‘Oil and Gas’
For further assistance, contact email@example.com.