Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Select Query from 2 Tables

Posted on 2008-06-19
2
Medium Priority
?
226 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

885 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