Solved

Select Query from 2 Tables

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

820 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