Re: Select Statement: Join vs Inner Select
From: SriSamp (ssampath_at_sct.co.in)
Date: 03/31/04
- Next message: David Portas: "Re: Calculate the total time in minute between 2 dates"
- Previous message: Jason: "Q: Select Statement: Join vs Inner Select"
- In reply to: Jason: "Q: Select Statement: Join vs Inner Select"
- Next in thread: Jason: "Re: Select Statement: Join vs Inner Select"
- Reply: Jason: "Re: Select Statement: Join vs Inner Select"
- Reply: Anith Sen: "Re: Select Statement: Join vs Inner Select"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 31 Mar 2004 16:11:21 +0530
The JOIN will definitely perform much better. In (2), the SELECT statement
will be executed for each row, which is huge overhead. Also, if you need
multiple columns from the same table, you will have to write repeated
SELECTs using the same join condition, which can severely hamper
performance. Using JOINs however, you can join the tables based on the keys
and then extract as many columns as you want. The execution plan also will
be much simpler and optimal.
Also, if you are executing this query from your VB app each time, SQL Server
will have to prepare an execution plan for each call. Rather, encapsulate
this as a stored procedure and call the stored procedure from your app. This
way, the plan is optimized and stored once and you also increase maintenance
of your code, since you can change your procedure code without affecting
your client.
-- HTH, SriSamp Please reply to the whole group only! http://www32.brinkster.com/srisamp "Jason" <jasonserv@hotmail.com> wrote in message news:uzh5gswFEHA.3064@tk2msftngp13.phx.gbl... > Says I have 2 tables: tbTran & tbUser. > Says the table has these fields: > tbTran (SeqNo, UserID, AuthUserID, ...) > tbUser(UserID, UserName, ...) > > Now, i need to list our the details of the transactions including the > username. I have 2 options here: > 1. Using Join table: "Select tbTran.SeqNo, tbTran.UserID, tbUser1.UserName, > tbTran.AuthUserID, tbUser2.UserName As AuthUserName From ((tbTran Left Join > tbUser tbUser1 On tbUser1.UserID=tbTran.UserID) Left Join tbUser tbUser2 On > tbUser2.UserID=tbTran.AuthUserID)" > > 2. Using Inner Select: "Select SeqNo, UserID, (Select UserName From tbUser > Where UserID = tbTran.UserID) As UserName, AuthUserID, (Select UserName From > tbUser Where UserID = tbTran.AuthUserID) As AuthUserName" > > This is only a simple illustration of the problem, some times the join table > can be as many as 10 tables. What I concerned about is the performance of > these 2 statements, which one would give better performance when running > from within a VB app connecting to a SQL Server? Please give me some advice, > thanks. > > Regards, > Jason > >
- Next message: David Portas: "Re: Calculate the total time in minute between 2 dates"
- Previous message: Jason: "Q: Select Statement: Join vs Inner Select"
- In reply to: Jason: "Q: Select Statement: Join vs Inner Select"
- Next in thread: Jason: "Re: Select Statement: Join vs Inner Select"
- Reply: Jason: "Re: Select Statement: Join vs Inner Select"
- Reply: Anith Sen: "Re: Select Statement: Join vs Inner Select"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|