GoldMine SQL Query- Primary Contacts and Primary Email Address with Email & Mail Merge Code

The following is a SQL Query that will display the Primary Contact with their Mailing Address, Email Address and the associated Email Merge Code and Mail Merge Code.

Select c1.Accountno, c1.Company,  c1.City, c1.Address1, c1.State, c1.Zip, cs.ADDRESS2 as Primary_Contact, cs.CONTSUPREF as Email_Address, cs.Mergecodes as Email_Merge, c1.Mergecodes as Mail_Merge,
From contsupp as cs, contact1 as c1
Where (cs.rectype = ‘P’ and = ‘E-mail Address’) and c1.key1 = ‘CUSTOMER’ and substring(,2,1)=’1′ and c1.accountno=cs.accountno