Solved

Select Query from 2 Tables

Posted on 2008-06-19
2
191 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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