Solved

GoldMine SQL Query  (Stuck)

Posted on 2004-09-25
3
265 Views
Last Modified: 2008-02-01
Can someone help me fine tune this query, It is taking too long so I must be doing something wrong.


select
      contact1.company,
      contact1.contact,
      contsupp.address2 as EM_Contact,
      contsupp.contsupref,
      contsupp.zip
      from contsupp join contact1
      on contact1.accountno=contsupp.accountno and
      contsupp.contact = 'E-mail Address'
      where
      contact1.accountno in
      (select * from
      contact1,
      conthist,
      contact2,
      contsupp
      where contact1.accountno=conthist.accountno and
      contact1.accountno = contact2.accountno and
      conthist.ref like
      '%Seminar Approaching%' and
      contact2.umarket = 'New York' or contact2.umarket = 'New Jersey')
0
Comment
Question by:ratzephyr
  • 2
3 Comments
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12151039
Try this:

SELECT c1.company, c1.contact, cs.address2 as EM_Contact, cs.contsupref, cs.zip
FROM contsupp cs
 JOIN contact1 c1 ON c1.accountno = cs.accountno
 JOIN contact2 c2 ON c1.accountno = c2.accountno
 JOIN conthist ch ON c1.accountno=ch.accountno
WHERE cs.contact = 'E-mail Address'
 AND ch.ref like '%Seminar Approaching%'
 AND c2.umarket IN ('New York','New Jersey')

Indexes on contsupp(contact) and on contact2(umarket) will help performance, as well as on all accountno columns, if these don't already have indexes.
0
 

Author Comment

by:ratzephyr
ID: 12151129
jdlambert1

Your query is pulling everything four times
0
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 250 total points
ID: 12151133
Ah, add the "Distinct" keyword:

SELECT Distinct c1.company, c1.contact, cs.address2 as EM_Contact, cs.contsupref, cs.zip
FROM contsupp cs
 JOIN contact1 c1 ON c1.accountno = cs.accountno
 JOIN contact2 c2 ON c1.accountno = c2.accountno
 JOIN conthist ch ON c1.accountno=ch.accountno
WHERE cs.contact = 'E-mail Address'
 AND ch.ref like '%Seminar Approaching%'
 AND c2.umarket IN ('New York','New Jersey')
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now