Solved

GoldMine SQL Query  (Stuck)

Posted on 2004-09-25
3
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

622 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