Solved

GoldMine SQL Query  (Stuck)

Posted on 2004-09-25
3
263 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

743 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

13 Experts available now in Live!

Get 1:1 Help Now