Solved

Optimize SQL JOIN statements for DataGrid

Posted on 2002-05-21
4
190 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

785 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