Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 24th, 2004, 05:35 AM
JimH JimH is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 JimH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Please Assist with Query Problem in Access

Hello All,

This is my first post here and I'm hoping I can find a good answer
to this seemingly tricky problem:

Here are some examples of queries that return the desired info.

----------------------------------------------------------------------

SELECT Companies.CompanyID, Companies.Name,
Companies.Symbol, Quotes.Price
FROM Companies
LEFT JOIN Quotes ON Companies.CompanyID =
Quotes.CompanyID
WHERE Quotes.QuoteID =
(SELECT TOP 1 Quotes.QuoteID From Quotes WHERE
Quotes.CompanyID = Companies.CompanyID) ORDER BY Quotes.QuoteID DESC
OR
Quotes.QuoteID NOT IN
(SELECT Quotes.QuoteID From Quotes)
----------------------------------------------------------------------

SELECT Companies.CompanyID, Companies.Name,
Companies.Symbol, Quotes.Price
FROM Companies
LEFT JOIN Quotes ON Companies.CompanyID =
Quotes.CompanyID
WHERE Quotes.QuoteID =
(SELECT TOP 1 Quotes.QuoteID From Quotes WHERE
Quotes.CompanyID = Companies.CompanyID ORDER BY Quotes.QuoteID DESC)
OR
Quotes.QuoteID NOT IN
(SELECT Quotes.QuoteID From Quotes)

-----------------------------------------------------------------------
These queries take absolutely forever to execute (forever = >3 minutes)
despite attemps to optimize indexes and default sort order and using only
a small test database with < 10K records. The query needs to run nearly as
fast as this one does:

SELECT Companies.CompanyID, Companies.Name,
Companies.Symbol, Quotes.Price
FROM Companies
LEFT JOIN Quotes ON Companies.CompanyID =
Quotes.CompanyID
WHERE Quotes.QuoteID =
(SELECT TOP 1 Quotes.QuoteID From Quotes WHERE
Quotes.CompanyID = Companies.CompanyID)
OR
Quotes.QuoteID NOT IN
(SELECT Quotes.QuoteID From Quotes)

------------------------------------------------------

Which executes in less than 1 second.


Thanks for any ideas,

JimH

Reply With Quote
  #2  
Old February 26th, 2004, 06:11 AM
JimH JimH is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 JimH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well if anyone is interested:

I found a query that does work:

SELECT [companies].[companyid], [companies].[name], [companies].[symbol], [quotes].[price]
FROM (companies LEFT JOIN [select max(quoteid) as maxofquoteid, companyid from quotes group by companyid]. AS q1 ON [companies].[companyid]=q1.companyid) LEFT JOIN quotes ON q1.maxofquoteid=[quotes].[quoteid];


However this query only works from within Access. I need to execute this query from inside my vb app using an ADO connection obejct. The syntax is often a little different when using ADO. The question now is can anyone translate into ADO SQL?

Reply With Quote
  #3  
Old February 26th, 2004, 04:46 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Store the query in Access, and call it from your VB - it's the same as calling a Stored Procedure.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Please Assist with Query Problem in Access


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway