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 8972535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:14:23+00:00 2026-06-15T18:14:23+00:00

The original query returns 160k rows. When I add the LEFT OUTER JOIN: LEFT

  • 0

The original query returns 160k rows. When I add the LEFT OUTER JOIN:

LEFT OUTER JOIN Table_Z Z WITH (NOLOCK) ON A.Id = Z.Id

the query returns only 150 rows. I’m not sure what I’m doing wrong.

All I need to do is add a column to the query, which will bring back a code from a different table. The code could be a number or a NULL. I still have to display NULL, hence the reason for the LEFT join. They should join on the “id” columns.

SELECT <lots of stuff> + the new column that I need (called "code").
FROM 
    dbo.Table_A A WITH (NOLOCK)
INNER JOIN 
    dbo.Table_B B WITH (NOLOCK) ON A.Id = B.Id AND A.version = B.version

--this is where I added the LEFT OUTER JOIN. with it, the query returns 150 rows, without it, 160k rows.    
LEFT OUTER JOIN 
    Table_Z Z WITH (NOLOCK) ON A.Id = Z.Id
LEFT OUTER JOIN 
    Table_E E WITH (NOLOCK) ON A.agent = E.agent
LEFT OUTER JOIN 
    Table_D D WITH (NOLOCK) ON E.location = D.location
                            AND E.type = 'Organization'
                            AND D.af_type = 'agent_location'
INNER JOIN 
    (SELECT X , MAX(Version) AS MaxVersion 
     FROM LocalTable WITH (NOLOCK) 
     GROUP BY agemt) P ON E.agent = P.location AND E.Version = P.MaxVersion

Does anyone have any idea what could be causing the issue?

  • 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-15T18:14:24+00:00Added an answer on June 15, 2026 at 6:14 pm

    When you perform a LEFT OUTER JOIN between tables A and E, you are maintaining your original set of data from A. That is to say, there is no data, or lack of data, in table E that can reduce the number of rows in your query.

    However, when you then perform an INNER JOIN between E and P at the bottom, you are indeed opening yourself up to the possibility of reducing the number of rows returned. This will treat your subsequent LEFT OUTER JOINs like INNER JOINs.

    Now, without your exact schema and a set of data to test against, this may or may not be the exact issue you are experiencing. Still, as a general rule, always put your INNER JOINs before your OUTER JOINs. It can make writing queries like this much, much easier. Your most restrictive joins come first, and then you won’t have to worry about breaking any of your outer joins later on.

    As a quick fix, try changing your last join to P to a LEFT OUTER JOIN, just to see if the Z join works.

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

Sidebar

Related Questions

My original query returns 7975 rows. Adding a where clause, I receive 7917 rows.
I am adding a 5th table to an existing join. The original query will
I have written a Linq query to do an outer join on multiple columns.
I'm not a real big TSSQL expert. We have a query that returns almost
Here is original Query :, it generates o/p with two columns name (label, count)
Suppose we got a original query as follows: SELECT A, B, C FROM tblA
Original SQL query is this; SELECT id,post_title,post_date FROM wp_posts where id='1' When I retrieve
Original Question: i read that for RESTful websites. it is not good to use
I'm working with a query that has a column named Date. The original query
A query in a system I maintain returns QID AID DATA 1 2 x

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.