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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:43:26+00:00 2026-06-05T09:43:26+00:00

This is probably a simple question for someone who is an sql database administrator,

  • 0

This is probably a simple question for someone who is an sql database administrator, but I’m a C# guy who only dabbles into the databases long enough to get them working when necessary.

I’ve got a new database I designed that only has a very little bit of data in it.

I need a query that will be used for generating my view, but I can never seem to understand how/when to use an INNER verses the LEFT join.

A Packet can have multiple Request entries (one person requests 5 different parts), and each Request entry can have different Action entries (on hold, cancelled, special order, complete, etc).

ProductionDatabase

I’d like to create a query that produces the following Data Table:

SELECT
  P.EmpID AS Requestor, P.DateStamp AS Submitted,
  T.Description AS RequestType, L.Description AS Line, R.PartNo, R.Workorder, R.Qty,
  RT.Description AS ReasonType, S.Description AS Status, A.EmpID AS Stator, A.DateStamp AS Stated, R.MTF
FROM Packet AS P
  LEFT OUTER JOIN Request AS R ON (R.PacketID=P.ID)
  LEFT OUTER JOIN Action AS A ON (A.RequestID=R.ID)
  LEFT OUTER JOIN RequestType AS T ON (R.RequestTypeID=T.ID)
  LEFT OUTER JOIN Line AS L ON (R.LineID=L.ID)
  LEFT OUTER JOIN ReasonType AS RT ON (R.ReasonTypeID=RT.ID)
  LEFT OUTER JOIN Status AS S ON (A.StatusID=S.ID)

This returns 5 rows, but there are a few NULL entries for Status, Stator, and Stated.

So, I tried writing this with an INNER JOIN:

SELECT
  P.EmpID AS Requestor, P.DateStamp AS Submitted,
  T.Description AS RequestType, L.Description AS Line, R.PartNo, R.Workorder, R.Qty,
  RT.Description AS ReasonType, S.Description AS Status, A.EmpID AS Stator, A.DateStamp AS Stated, R.MTF
FROM Packet AS P
  INNER JOIN Request AS R ON (R.PacketID=P.ID)
  INNER JOIN Action AS A ON (A.RequestID=R.ID)
  INNER JOIN RequestType AS T ON (R.RequestTypeID=T.ID)
  INNER JOIN Line AS L ON (R.LineID=L.ID)
  INNER JOIN ReasonType AS RT ON (R.ReasonTypeID=RT.ID)
  INNER JOIN Status AS S ON (A.StatusID=S.ID)

The NULL entries are now gone, but now I only have 3 rows returned.

How do I know which version I should be using? …or, should I be using a combination of LEFT and INNER joins?

  • 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-05T09:43:28+00:00Added an answer on June 5, 2026 at 9:43 am

    How do I know which version I should be using?

    Only you can answer that question. Did you want the 5 rows with null or the 3 rows with no nulls?

    As you noted from your results, a LEFT JOIN will return a record even when there is no matching record in the table you are joining on (hence the null values). An INNER JOIN will only return a record if there is a matching record in the table you are joining on (which is why you see 3 results instead of 5).

    Take a look at this for an excellent visual explanation of joins.

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

Sidebar

Related Questions

This is probably a simple question, but the answer is eluding me. I have
This is probably a simple question, but I'm trying to lookup the constant name
This is probably a simple question but I can't seem to figure out how
This is probably a simple question, but i have been unable to find a
This is probably a simple question but I am developing a web app in
This is probably a very simple question for you SQL folks out there. I
This is probably a really simple question but one I've never quite worked out
I know this is probably a very simple question but how would I do
I'm new to Xcode. This is probably a very simple question to you, but
This is a very simple, probably too simple question but I'm afraid my limited

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.