Results 1 to 3 of 3

Thread: SQL Tables

  1. #1
    Shairal is offline Member
    Join Date
    Apr 2009
    Posts
    6

    Default SQL Tables

    Can anyone tell me if there is a SQL table where I can find email addresses that have opted out of a newsletter campaign?

    Thanks in advance!

  2. #2
    crsoftware is offline Sugar Community Member
    Join Date
    Jul 2007
    Posts
    33

    Default Re: SQL Tables

    Hopefully, some of this helps. It depends on what version of Sugar you're using. If you use 5.x and you use the 'Opted out' check-box on the contact's edit screen for your newsletters, that info can be pulled from the email_addresses table.

    Code:
    SELECT
     email_address
    FROM
     email_addresses
    WHERE
     opt_out = 1
    That would just give you a list of email addresses. If you want to associate contact names with these email addresses it becomes more complicated. You have to join to the contacts table using the email_addr_bean_rel table.

    Code:
    SELECT
     c.first_name,
     c.last_name,
     email.email_address
    FROM
     contacts c
     JOIN email_addr_bean_rel bean ON (c.id = bean.bean_id AND bean.bean_module = 'Contacts')
     JOIN email_addresses email ON (bean.email_address_id = email.id)
    WHERE
     email.opt_out = 1
    The interesting thing about the second query is that it could return more results than the first query if two or more people have the same email address and have opted out. The first query will only show the opted out email address once, but the second will show it two or more times because of the association with the different contacts.

    The first query could have returned...

    Code:
    bob@abc.com
    mary@345.com
    it_dept@xyz.com
    ...but the second could return...

    Code:
    Bob Smith bob@abc.com
    Mary Jones mary@345.com
    John Collins it_dept@xyz.com
    Jeff Williams it_dept@xyz.com
    George Smart it_dept@xyz.com

  3. #3
    Shairal is offline Member
    Join Date
    Apr 2009
    Posts
    6

    Default Re: SQL Tables

    Thank you so much for your assistance!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. save in two different tables at once
    By igivello in forum Developer Help
    Replies: 4
    Last Post: 2009-04-15, 10:58 AM
  2. Replies: 3
    Last Post: 2008-03-28, 01:17 PM
  3. Replies: 0
    Last Post: 2008-01-28, 05:05 PM
  4. Tables Map
    By Thomas in forum Feature Requests
    Replies: 0
    Last Post: 2004-09-04, 11:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •