Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query takes too long to run - help me optimize

Status
Not open for further replies.

Quimbly

Programmer
Oct 24, 2002
33
0
0
CA
Hi everyone,
I've been trying to get this query to run quicker. Currently it just takes too long. Does anyone have any suggestions about optimizing it?

SELECT DISTINCT outerquery.name, "group" FROM analog outerquery WHERE EXISTS (SELECT * FROM analog innerquery WHERE innerquery."group" = outerquery."group" AND innerquery.ptnum != outerquery.ptnum AND innerquery.name LIKE 'ZZZ_%') AND uterquery.name LIKE 'ZZZ_%'
 
for one....get rid of the 'select *'...just select something small like an id or something. Maybe do a 'Select Top 1 id'. I don't use subqueries much, so I don't know if that second part would help at all.

The %'s would be slowing it down a lot too. I'm not sure how you could get rid of those though.
 
Where are your indexes? Where does the execution plan say the costs are?

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
 
EXISTS() tells optimizer to perform existance test only, so SELECT * or SELECT TOP 1 or SELECT 1 shouldn't matter.

LIKE 'ZZZ_%' is optimizable... assuming that [name] column is indexed. But note that '_' is also wildchar character.

How many records has each table and how many records returns this query?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top