Re: SQL Query Performance
From: Wayne Snyder (wsnyder_at_computeredservices.com)
Date: 05/19/04
- Next message: Aaron Collver: "Re: DB-Library error 10038"
- Previous message: Ben Reese: "Convert to Hexidecimal"
- In reply to: agustina_s: "Re: SQL Query Performance"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 19 May 2004 07:53:16 -0400
What you should do is
set statistics io on
set statistics time on
Execute the query and see which is faster.
Also look at the execution plan in Query Analyzer to ensure proper indexes
are being used....
-- Wayne Snyder, MCDBA, SQL Server MVP Mariner, Charlotte, NC www.mariner-usa.com (Please respond only to the newsgroups.) I support the Professional Association of SQL Server (PASS) and it's community of SQL Server professionals. www.sqlpass.org "agustina_s" <agustina_s.16hul4@mail.mcse.ms> wrote in message news:agustina_s.16hul4@mail.mcse.ms... > > Hi.. > > Is there any specific place where I can find which SQL Query is more > efficient?. > > Is INNER JOIN is faster or Select ... Where ID in (SELECT ...) is > faster? > > I have two tables: > 1.FLEET (The number of rows is not so much) > Attributes : > Company_Id (PK) > Fleet_Id (PK) > Fleet_Name > Fleet_Description > > 2.USER_PRIVILEGE (The number of rows can reach up to 3 times the number > of row in fleet table) > Attributes : > Company_Id (PK) > Fleet_Id (PK) > User_Id (PK) > Privilege_Id(PK) > Comment > Category > > I want to select Fleet_Id and Fleet_Name from fleet table > Where the current user has privilege. > > I have two possible select statement : > > 1.Option 1 > SELECT Fleet_Name, Fleet_Id > FROM FLEET > WHERE (Company_Id = 2) AND (Fleet_Id IN > (SELECT fleet_id > FROM user_privilege > WHERE user_id = 11 AND company_id = 2 AND privilege_id = > 1)) > ORDER BY Fleet_Name > > 2.Option 2 > > SELECT F.Fleet_Name, F.Fleet_Id > FROM USER_PRIVILEGE U INNER JOIN > FLEET F ON U.Fleet_Id = F.Fleet_Id > WHERE (F.Company_Id = 2) AND (U.Privilege_Id = 1) AND (U.User_Id = > 11) > ORDER BY F.Fleet_Name > > Actually which one is faster. Is SQL Statement with INNER JOIN (Option > 2) can be executed faster than the one with double Select > Statement(Option 1)? > > Any siggestion is welcomed. > Thank you very much. > > > > -- > agustina_s > ------------------------------------------------------------------------ > Posted via http://www.mcse.ms > ------------------------------------------------------------------------ > View this thread: http://www.mcse.ms/message689772.html >
- Next message: Aaron Collver: "Re: DB-Library error 10038"
- Previous message: Ben Reese: "Convert to Hexidecimal"
- In reply to: agustina_s: "Re: SQL Query Performance"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|