Solved

Select Query from 2 Tables

Posted on 2008-06-19
2
167 Views
Last Modified: 2011-10-19
Need to select records that match and then those that don't match from the 2 tables (See attached)
Would like to compare Table A statid to Table B statid and if those don't match, try to match on Table A id2 with TableB Id2 (or vice versa..whatever works).
 I have to account for NULLS and blanks in the statid & id2 fields. I have thousands of recs in each file.
Thank you!
AandBFiles.xls
0
Comment
Question by:lbarnett419
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21826801
those that do match:
SELECT * FROM tableA a JOIN tableB b on a.statid = b.statid

those in A but not in B:
SELECT a.* FROM tableA a LEFT JOIN tableB b on a.statid = b.statid WHERE b.statid IS NULL

those in B but not in A:
SELECT a.* FROM tableB B LEFT JOIN tableA a on a.statid = b.statid WHERE a.statid IS NULL
0
 

Author Closing Comment

by:lbarnett419
ID: 31468982
Thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now