Thanks to visit codestin.com
Credit goes to mtcextendee.com

Unlimited SQL

Easily use custom SQL queries in your segments and campaigns.

The Unlimited SQL plugin lets you:

  • Add custom SQL filters to segments (Segment Filter)
  • Run SQL queries as campaign actions (Campaign Action)
  • Use SQL queries as campaign conditions (Campaign Condition)
  • Test your SQL queries directly in the Mautic UI before using them

You can use placeholders like :contactId, :campaignId, and :eventId in your queries. The plugin will safely replace them with the right values for each contact or campaign step.

Features

  • Segment Filter — Add contacts to segments based on your own SQL logic. Example: only include contacts with more than 5 page hits.
  • Campaign Action — Run a SQL query for every contact that reaches a campaign step. Example: update an external CRM table when a contact hits a step.
  • Campaign Condition — Branch your campaign based on the result of a SQL query. Example: check if a contact is in a VIP table and send them down a special path.
  • Testing Area — Select a contact and test your SQL query before saving.

How It Works

  1. Create an SQL Entry — Go to Unlimited SQL in the Mautic menu and create a new entry. Choose the type (Segment Filter, Campaign Action, or Campaign Condition), write your SQL, and save.
  2. Test your query — Use the built-in testing area to select a contact and see if your query works as expected.
  3. Use in Segments or Campaigns — For segments: add a filter of type "Unlimited SQL Filters" and select your SQL entry. For campaigns: add an action or condition and select your SQL entry.

Tip: Always use placeholders (:contactId, etc.) for security. The plugin uses parameter binding to prevent SQL injection.

Installation

Once you receive a confirmation email, you can download the latest version of the bundle using the provided link.

Step 1: Copy the plugin

Place the plugin folder in plugins/MauticUnlimitedSQLBundle

Step 2: Clear cache

php bin/console cache:clear

Step 3: Reload plugins list

php bin/console mautic:plugins:reload

Step 4: Re-generate assets

php bin/console mautic:assets:generate

After installation, go to Settings > Plugins in Mautic and make sure the plugin is enabled.

FAQ

Is SQL knowledge required?

Basic SQL knowledge is helpful, but the plugin is designed to be user-friendly. You can use the built-in testing area to check your queries before using them.

Can I test my SQL queries before deployment?

Yes! The plugin includes a testing area where you can select a contact and see the result of your SQL query before saving.

Which Mautic versions are supported?

Compatible with Mautic 4, 5, 6, and 7.

What placeholders can I use?

  • :contactId — Always available, replaced with the current contact's ID.
  • :campaignId and :eventId — Available for campaign actions and conditions.

Is it safe to use custom SQL?

Yes, as long as you use the provided placeholders. The plugin uses parameter binding to prevent SQL injection.

Where do I find Unlimited SQL after installing?

Go to the "Unlimited SQL" section in the Mautic menu. From there, you can create, test, and manage your SQL entries.

Examples

Find contacts with more than 5 page hits:

SELECT 1 FROM page_hits ph WHERE ph.lead_id = :contactId HAVING COUNT(ph.id) > 5

At least one email read in the last 12 months:

SELECT 1 FROM email_stats es WHERE es.lead_id = :contactId AND es.is_read = 1 AND es.date_sent > NOW() - INTERVAL 1 YEAR

Use this as a segment filter or campaign condition to target contacts who have engaged with at least one email in the last 12 months.

Check if contact exists in an external table:

SELECT 1 FROM vip_customers ext WHERE ext.mautic_contact_id = :contactId LIMIT 1

Update an external table when a campaign step is reached:

UPDATE crm_sync SET campaign_step_reached = NOW(), last_campaign_id = :campaignId WHERE mautic_contact_id = :contactId

Find contacts who have not opened any email in the last 6 months:

SELECT 1 FROM email_stats es WHERE es.lead_id = :contactId AND es.is_read = 1 AND es.date_sent > NOW() - INTERVAL 6 MONTH

Use this as a negative segment filter.

Find contacts with at least 3 form submissions:

SELECT 1 FROM form_submissions fs WHERE fs.lead_id = :contactId HAVING COUNT(fs.id) >= 3

Check if contact is assigned to a specific owner:

SELECT 1 FROM leads l WHERE l.id = :contactId AND l.owner_id = 42