Solved

Optimize SQL JOIN statements for DataGrid

Posted on 2002-05-21
4
188 Views
Last Modified: 2010-05-02
I'm using VB6 against an SQL Server database.
I'm using an ADO recordset to populate a datagrid control.
I noticed that the grid performs better with different sql select strings.

I need help in writing the best sql select string to populate my grid.
Mostly, on this select from two tables with a common id:
This one performs slow:
"SELECT * FROM Cuts, Appropriations WHERE Cuts.AppropId = Appropriations.Id"

While this string is faster:
Select * from cuts join Appropriations on cuts.appropid = Appropriations.id

Can anyone suggest the best way to write sql statements which draw data from two or more tables?

Thanks
John

0
Comment
Question by:jtrapat1
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Joe_Griffith earned 50 total points
ID: 7025596
Do you really need everything from both tables?  You might try just selecting the specific items you need.
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 7025613
<< Select * from cuts join Appropriations on cuts.appropid = Appropriations.id >>

IS better and the only way I know to improve on this is to PERHAPS create an index the column cuts.appropid, if one does not exist.  This may or may not help, depending on the data...  Is Appropriations.id a one-to-many relationship to cuts.appropid or vice versa or one-to-one... These things are important to know.
0
 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 7030329
I'm actually surprised that selecting specific items had an effect.  I thought I read somewhere that SELECT * was faster than selecting individual items.  Of course if the table contained many fields and you only need a few it would surely be faster to select specific ones.
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 7030386
It is always faster to retrieve less than to retrieve more...  I would suspect that just stating column names alone saves the overhead of SQL server saying to itself, "Oh, he wants it all, what are they now?" and having to build a list...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA saving file message display 5 56
Exit a vb6 apps when a calling it apps closes 15 43
SLMGR Switches Are Not Working On KMS Host 3 69
Recommendation vb6 to vb.net or others 14 112
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

896 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

14 Experts available now in Live!

Get 1:1 Help Now