Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:05:17+00:00 2026-05-27T18:05:17+00:00

I’m building a query that needs data from 5 tables. I’ve been told by

  • 0

I’m building a query that needs data from 5 tables.
I’ve been told by a DBA in the past that specifying a list of columns vs getting all columns (*) is preferred from some performance/memory aspect.
I’ve also been told that the database performs a JOIN operation behind the scenes when there’s a list of tables in the FROM clause, to create one table (or view).

The existing database has very little data at the moment, as we’re at a very initial point. So not sure I can measure the performance hit in practice.
I am not a database pro. I can get what data I need. The dillema is, at what price.

Added: At the moment I’m working with MS SQL Server 2008 R2.

My questions are:

  1. Is there a performance difference and why, between the following:
    a. SELECT … FROM tbl1, tbl2, tbl3 etc for simplicity? (somehow I feel that this might be a performance hit)
    b. SELECT … FROM tbl1 inner join tbl2 on … inner join tbl3 on … etc (would this be more explicit to the server and save on performance/memory)?
    c. SELECT … FROM (select x,y,z from tbl1) as t1 inner join … etc (would this save anythig? or is it just extra select statements that create more work for the server and for us)?

  2. Is there yet a better way to do this?

Below are two queries that both get the slice of data that I need. One includes more nested select statements.

I apologize if they are not written in a standard form or helplessly overcomplicated – hopefully you can decipher. I try to keep them organized as much as possible.

Insights would be most appreciated as well.
Thanks for checking this out.

5 tables: devicepool, users, trips, TripTracker, and order

Query 1 (more select statements):

SELECT
      username, 
      base.devid devid, 
      tripstatus, 
      stops, 
      stopnumber, 
      [time], 
      [orderstatus], 
      [destaddress]

FROM    
((
 (  SELECT 
           username, 
           devicepool.devid devid,
           groupid
    FROM
           devicepool INNER JOIN users 
           ON devicepool.userid = users.userid 

     WHERE devicepool.groupid = 1
 ) 
 AS [base] 

 INNER JOIN

 (
      SELECT 
              tripid, 
              [status] tripstatus, 
              stops, 
              devid,
              groupid

      FROM 
              trips 
 ) 
 AS [base2]

 ON base.devid = base2.devid AND base2.groupid = base.groupid

 INNER JOIN

 (
     SELECT 
            stopnumber, 
            devid, 
            [time], 
            MAX([time]) OVER (PARTITION BY devid) latesttime 
     FROM 
            TripTracker
 ) 

 AS [tracker] 
 ON tracker.devid = base.devid AND [time] = latesttime)

 INNER JOIN

 (
      SELECT 
            [status] [orderstatus], 
            [address] [destaddress], 
            [tripid], 
            stopnumber orderstopnumber 
      FROM [order]
 ) 
 AS [orders] 

 ON orders.orderstopnumber = tracker.stopnumber)

Query 2:

SELECT
      username, 
      base.devid devid, 
      tripstatus, 
      stops, 
      stopnumber, 
      [time], 
      [orderstatus], 
      [destaddress]

FROM    
((
 (  SELECT 
           username, 
           devicepool.devid devid,
           groupid
    FROM
           devicepool INNER JOIN users 
           ON devicepool.userid = users.userid 

     WHERE devicepool.groupid = 1
 ) 
 AS [base] 

 INNER JOIN

     trips

 ON base.devid = trips.devid AND trips.groupid = base.groupid

 INNER JOIN

 (
     SELECT 
            stopnumber, 
            devid, 
            [time], 
            MAX([time]) OVER (PARTITION BY devid) latesttime 
     FROM 
            TripTracker
 ) 

 AS [tracker] 
 ON tracker.devid = base.devid AND [time] = latesttime)

 INNER JOIN

    [order]

 ON [order].stopnumber = tracker.stopnumber)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:05:18+00:00Added an answer on May 27, 2026 at 6:05 pm

    Is there a performance difference and why, between the following: a.
    SELECT … FROM tbl1, tbl2, tbl3 etc for simplicity? (somehow I feel
    that this might be a performance hit) b. SELECT … FROM tbl1 inner
    join tbl2 on … inner join tbl3 on … etc (would this be more
    explicit to the server and save on performance/memory)? c. SELECT …
    FROM (select x,y,z from tbl1) as t1 inner join … etc (would this
    save anythig? or is it just extra select statements that create more
    work for the server and for us)?

    a) and b) should result in the same query plan (although this is db-specific). b) is much preferred for portability and readability over a). c) is a horrible idea, that hurts readability and if anything will result in worse peformance. Let us never speak of it again.

    Is there yet a better way to do this?

    b) is the standard approach. In general, writing the plainest ANSI SQL will result in the best performance, as it allows the query parser to easily understand what you are trying to do. Trying to outsmart the compiler with tricks may work in a given situation, but does not mean that it will still work when the cardinality or amount of data changes, or the database engine is upgraded. So, avoid doing that unless you are absolutely forced to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.