Solved

Optimize SQL JOIN statements for DataGrid

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

746 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

11 Experts available now in Live!

Get 1:1 Help Now