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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:48:44+00:00 2026-05-11T07:48:44+00:00

I have a pathological issue with SQL, so I usually sort all of my

  • 0

I have a pathological issue with SQL, so I usually sort all of my database issues by building quickie software applications to handle my SQL problems.

(as I am also doing in this case)

Thanks to StackOverflow I think I can be shamed into correctness, so I would like to learn how to make this kind of SQL troubleshooting in actual SQL or T-SQL itself (if possible):

I have:

database DB1 Table A (unitNo, BuildingNo)

database DB2 Table B (unitNo, BuildingNo)

  1. I want to come up with the Units (unit numbers) existing on Table A from Database DB1 which do not exist on table B from Database DB2 and vice versa.

  2. There can be more than one unit with the same unit number, this will happen because the same unit number can be given to units of different buildings.

  3. I do not have write access to any of the databases.

I hope this isn’t seen as a ‘gimme teh codz’ post, I would like to know how people with more SQL fluency than me sort this kind of algorithm, posts to tutorials or hints are more than welcomed, no full code required, but if it helps to makes sense, then please do.

At first I thought I could just get all the unit numbers from one table and exclude them on a select from the other like so:

select concated.unit from  ( SELECT (  unitNo + ',' + CONVERT(varchar(12), BuildingNo) ) as unit FROM A) concated  having concated.unit not in  ( '201,1', '202,1', '203,1', '204,1', '205,1', '206,1', [...] 

This would usually work, but the number of units from any one table is immense, trying this crashes the SQL server with:

‘ran out of stack space’

Thanks,

Ric

  • 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. 2026-05-11T07:48:44+00:00Added an answer on May 11, 2026 at 7:48 am

    I think you’re looking for full outer join. Which gives you the unit numbers you asked for in Part 1.

    Select     A.UnitNumber, B.UnitNumber from    DB1.dbo.TableA A FULL OUTER JOIN DB2.dbo.TableB B         on A.UnitNumber = B.UnitNumber        and A.BuildingNumber = B.BuildingNumber Where    A.UnitNumber is null or B.UnitNumber is null 

    Other queries that might be of interest I’ve outlined below.

    This gives you the records in A not in B.

    Select     A.UnitNumber From     DB1.dbo.TableA A Left Join DB2.dbo.TableB B          on A.UnitNumber = B.UnitNumber          and A.BuildingNumber = B.BuildingNumber Where     B.UnitNumber is null 

    And you just reverse it to find the records in B that aren’t in A.

    Select     B.UnitNumber From     DB2.dbo.TableB B left join DB1.dbo.TableA A          on B.UnitNumber = A.UnitNumber         and B.BuildingNumber = A.BuildingNumber Where     A.UnitNumber is null 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There is no difference. string is an alias of String.… May 11, 2026 at 12:29 pm
  • added an answer You can compile the js code inject into your SWF… May 11, 2026 at 12:29 pm
  • added an answer Just create three different forms, separate your fields between them… May 11, 2026 at 12:29 pm

Related Questions

I have a web-service that I will be deploying to dev, staging and production.
I have a .Net desktop application with a TreeView as one of the UI
I have a Queue<T> object that I have initialised to a capacity of 2,
My program, alas, has a memory leak somewhere, but I'll be damned if I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.