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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:43:38+00:00 2026-05-30T19:43:38+00:00

I will try to make my question sound as unconfusing as possible. I appologize

  • 0

I will try to make my question sound as unconfusing as possible. I appologize in advance for any wording mistakes as I try to phrase my question as best as I can:

Using T-SQL I need to write a join statement that gets me all the results that have a match in table A and table B

AND (!)

another join statement (or a continuation of the first join) that returns all the results from table A that DID NOT have a match in table B, BUT in this second result set I need to have one of the columns set to “N/A” to identify the records that didn’t have a match.

In other words, I need something that would return everything in table A but would also identify the rows that weren’t matched in B. That information is then used in a report.

Here is what I have so far:

I have the first part done:

LEFT OUTER JOIN dbo.chart B
ON B.UserName = A.user_name

That gets me the matching records and just the matching records

I tried adding this second join:

JOIN dbo.chart
ON NOT EXISTS (select * from B.UserName = A.user_name)

Hoping it would get me the non-matching records (I was planning to then use REPLACE on the column of interest to label that column “N/A”) but there is something clearly wrong with my synthax as that generates exceptions.

My question is what do I need to change to get me the results you need. I do know that I need to have at least one join as I have other part of the query to work with. I just don’t know if I need to have that one join return both sets of data of I actually do need a second one just for the non-matching records.

Hope this wasn’t too confusing. Any help would be greatly appreciated.

Thank you!

Update: I would just like to emphasize that the reason I considered using a second join instead of getting all of the results at once is because I need to correctly identify and label those rows that weren’t matched within everything that I get back.

  • 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-30T19:43:39+00:00Added an answer on May 30, 2026 at 7:43 pm

    Sample data:

    declare @TableA table
    (
      TableAID int,
      TableAName varchar(10)
    )
    
    declare @TableB table
    (
      TableBID int,
      TableBName varchar(10),
      TableAID int
    )
    
    insert into @TableA values
    (1, 'A 1'),
    (2, 'A 2'),
    (3, 'A 3')
    
    insert into @TableB values
    (1, 'B 1', 1),
    (2, 'B 2', 2)
    

    N/A instead of TableBName:

    select A.TableAName,
           coalesce(B.TableBName, 'N/A') as TableBName
    from @TableA as A
      left outer join @TableB as B
        on A.TableAID = B.TableAID
    

    Result:

    TableAName TableBName
    ---------- ----------
    A 1        B 1
    A 2        B 2
    A 3        N/A
    

    Extra column for N/A:

    select A.TableAName,
           B.TableBName,
           case when B.TableBID is null 
             then 'N/A' 
             else '' 
           end as TableBPresent
    from @TableA as A
      left outer join @TableB as B
        on A.TableAID = B.TableAID    
    

    Result:

    TableAName TableBName TableBPresent
    ---------- ---------- -------------
    A 1        B 1        
    A 2        B 2        
    A 3        NULL       N/A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will try to make this as straight forward as possible. This question does
I will try to make this as clear as I can, but if you
I will try to be as clear as possible because I can't get anybody
I will try and set the scene as best i can. *lights candle What
I am going to try to make this question as clear as I can.
What will be the code when I try to make a combo box read
I will try and illustrate my question with examples, I am attempting to create
I will try to keep this as simple as possible. I have a rather
I will try to be specific if I can - please be patient, first
HI, I have the following scenario which I will try to explain as best

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.