Advertisement

05.28.2008 at 08:17AM PDT, ID: 23438374
[x]
Attachment Details

Efficient SELECT statement

Asked by mmexchange in MS SQL Server, Databases Miscellaneous, SQL Query Syntax

The following doesn't seem very efficient, (two calls to another table):
SELECT MyID
 , TypeID
 , ( SELECT ChapID FROM PageTable WHERE PageID = TypeID ) AS ChapID
 , ( SELECT PageID FROM PageTable WHERE PageID = TypeID ) AS PageID
FROM MyTable1
Would something like this work? And would it be "more" efficient?
SELECT MyID
 , TypeID
 , ( SELECT ChapID, PageID FROM PageTable WHERE PageID = TypeID ) AS ChapID, PageID
FROM MyTable1
Start Free Trial
[+][-]05.28.2008 at 08:19AM PDT, ID: 21661214

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.28.2008 at 08:28AM PDT, ID: 21661314

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.28.2008 at 08:29AM PDT, ID: 21661318

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.28.2008 at 08:35AM PDT, ID: 21661389

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.28.2008 at 09:46AM PDT, ID: 21662051

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.29.2008 at 08:12AM PDT, ID: 21669857

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 08:16AM PDT, ID: 21669912

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, Databases Miscellaneous, SQL Query Syntax
Sign Up Now!
Solution Provided By: mark_wills
Participating Experts: 4
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628