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

  • Home
  • SEARCH
  • 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 8846611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:02:05+00:00 2026-06-14T12:02:05+00:00

I have a simple question regarding the dichotomy of joining two tables vs using

  • 0

I have a simple question regarding the dichotomy of joining two tables vs using 2 separate queries.

I was hoping to find an existing question, but my search didn’t yield much (most questions were for more complex problems).

For example, consider two tables, A and X, with a very simple schema:

Table A   +-------------+-------------+-------------+
          | Column A (*)| Column X(FK)| Column C    |
          +-------------+-------------+-------------+

Table X   +-------------+-------------+-------------+
          | Column X (*)| Column Y    | Column Z    |
          +-------------+-------------+-------------+

Where columns A and X are identity columns and primary keys (bigint). There is also an existing foreign key relationship for column X between tables A and X.

My question is, assuming both tables are sufficiently large (just say 500K rows), would I benefit more in terms of performance from using a single query (see Linq2Sql pseudo code below), or use two separate queries?

Option 1:

long aValue = 107;
DataContext dc = new DataContext();
var items = (from a in dc.TableA
             join x in dc.TableX
             on a.X equals x.X
             where a.A == aValue
             select new { a, x });

Option 2:

  • Just assume I write an SP that does 2 separate select statements in serial.

To further quantify the problem, you can assume for every value of A, there are only a few (0-5) rows that will be joined from Table Y, so the duplication of Table A data returned in the join is not significant.

I’m asking strictly form a DB server impact standpoint. So ignoring any client-side considerations, (e.g. roundtrip networking latency, L2S query building and data marshalling costs, etc.) my questions are:

  1. Which option will take less time to compute on the DB server?

  2. Which option will require less memory to evaluate the result?

  3. Which option is generally preferred, if there is a best practice?

Sorry if this sounds too rudimentary, but any insight will be appreciated.

Thanks,
– K.

  • 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-06-14T12:02:07+00:00Added an answer on June 14, 2026 at 12:02 pm

    Short answer: Trust the optimizer.

    A Single query (especially with a simple join) against a well indexed table will be more effecient than writing a set of serial SQL statements. I’m not an expert in LINQ, so I’m not sure what columns you’ll be returning with your pseudocode, but if the tables are properly indexed on appropriate hardware, you’ll be fine.

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

Sidebar

Related Questions

I have a simple question regarding jQuery selectors. I'm using the tablesorter and I
I have a pretty simple Rails question regarding encoding that I can't find an
I'm using Rails 3 with mongoid 2 and have a simple question regarding mongoid
I have a simple question regarding accessing member variables of a model object. I
Morning, simple stupid question. I have found post with similar issues but after reading
I have a simple question regarding code blocks within statements, and variables. My script
I have a simple question regarding how to write an always block in a
I have a simple question regarding Entity declaration in JPA. I have an entity
simple question regarding HQL(Hibernate query language) so i have user class , that can
I have a simple, general question regarding a real small issue that bothers me:

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.