SQL help needed please

greetings gurus

I am having trouble with the syntax of a query I'm trying to write.  Here is 
the situation, simpified to its essence:
C:/DB/A.mdb has tblNames with relevant fields CustID, CustName, CustEMail.
C:/DB/B.mdb has the same table and fields.
C:/DB/C.mdb also has the same table and fields.

Many of the names appear in 2 or 3 of the databases, but most names appear 
in only one of the three databases.

Here's what I am trying to do (so far without success)...

I want the values of CustID, CustName, CustEMail that are in A.mdb   
UNION
the values of  CustID, CustName, CustEMail that are in B.mdb.
Then I need to remove any doubles (same PK CustID) from the resulting 
recordset.
Finally, I need to EXCLUDE any of these remaining records that ALSO appear 
in C.mdb.

I would be SO greatful for help.   -  cinnie

0
Utf
2/12/2010 11:49:02 PM
access.queries 6343 articles. 1 followers. Follow

5 Replies
822 Views

Similar Articles

[PageSpeed] 8

On Fri, 12 Feb 2010 15:49:02 -0800, cinnie
<cinnie@discussions.microsoft.com> wrote:

You should link the tables from B and C to your A database. Give them
different names e.g. tblNamesB, tblNamesC.
Now the union query is trivial, and it will automatically exclude
duplicate records. However, your requirement is to exclude duplicate
PKs, which is a subtly different question. How about:
select * from tblNames
union
select * from tblNamesB where tblNamesB.CustID not in (select CustID
from tblNames)
I think you can figure out the rest.

-Tom.
Microsoft Access MVP


>greetings gurus
>
>I am having trouble with the syntax of a query I'm trying to write.  Here is 
>the situation, simpified to its essence:
>C:/DB/A.mdb has tblNames with relevant fields CustID, CustName, CustEMail.
>C:/DB/B.mdb has the same table and fields.
>C:/DB/C.mdb also has the same table and fields.
>
>Many of the names appear in 2 or 3 of the databases, but most names appear 
>in only one of the three databases.
>
>Here's what I am trying to do (so far without success)...
>
>I want the values of CustID, CustName, CustEMail that are in A.mdb   
>UNION
>the values of  CustID, CustName, CustEMail that are in B.mdb.
>Then I need to remove any doubles (same PK CustID) from the resulting 
>recordset.
>Finally, I need to EXCLUDE any of these remaining records that ALSO appear 
>in C.mdb.
>
>I would be SO greatful for help.   -  cinnie
0
Tom
2/13/2010 3:25:35 AM
If you have links in the A.mdb to the relevant table in B.Mdb and C.mdb then 
the following should work to give you a unique list of CustID, CustName, and 
CustEmail that are in either A or B and not in C.

SELECT A.CustID, A.CustName, A.CustEmail
FROM TableA LEFT JOIN TableC
ON TableA.CustID = TableC.CustID
WHERE TableC.CustID is Not Null
UNION
SELECT B.CustID, B.CustName, B.CustEmail
FROM TableB LEFT JOIN TableC
ON TableB.CustID = TableC.CustID
WHERE TableC.CustID is Not Null

If you want just one record per CustID and there are possible duplicates 
records because CustName or CustEmail differs then you can use the UNION query 
as the source for another query where you aggregate the data

SELECT CustID, First(CustName), First(CustEmail)
FROM qUnionQuery
GROUP BY CustID

IF you want the latter, you might change UNION to UNION ALL and see if that 
returns the results faster or slower.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

cinnie wrote:
> greetings gurus
> 
> I am having trouble with the syntax of a query I'm trying to write.  Here is 
> the situation, simpified to its essence:
> C:/DB/A.mdb has tblNames with relevant fields CustID, CustName, CustEMail.
> C:/DB/B.mdb has the same table and fields.
> C:/DB/C.mdb also has the same table and fields.
> 
> Many of the names appear in 2 or 3 of the databases, but most names appear 
> in only one of the three databases.
> 
> Here's what I am trying to do (so far without success)...
> 
> I want the values of CustID, CustName, CustEMail that are in A.mdb   
> UNION
> the values of  CustID, CustName, CustEMail that are in B.mdb.
> Then I need to remove any doubles (same PK CustID) from the resulting 
> recordset.
> Finally, I need to EXCLUDE any of these remaining records that ALSO appear 
> in C.mdb.
> 
> I would be SO greatful for help.   -  cinnie
> 
0
John
2/13/2010 3:35:58 PM
That does it! Thanks.
-- 
cinnie


"John Spencer" wrote:

> If you have links in the A.mdb to the relevant table in B.Mdb and C.mdb then 
> the following should work to give you a unique list of CustID, CustName, and 
> CustEmail that are in either A or B and not in C.
> 
> SELECT A.CustID, A.CustName, A.CustEmail
> FROM TableA LEFT JOIN TableC
> ON TableA.CustID = TableC.CustID
> WHERE TableC.CustID is Not Null
> UNION
> SELECT B.CustID, B.CustName, B.CustEmail
> FROM TableB LEFT JOIN TableC
> ON TableB.CustID = TableC.CustID
> WHERE TableC.CustID is Not Null
> 
> If you want just one record per CustID and there are possible duplicates 
> records because CustName or CustEmail differs then you can use the UNION query 
> as the source for another query where you aggregate the data
> 
> SELECT CustID, First(CustName), First(CustEmail)
> FROM qUnionQuery
> GROUP BY CustID
> 
> IF you want the latter, you might change UNION to UNION ALL and see if that 
> returns the results faster or slower.
> 
> John Spencer
> Access MVP 2002-2005, 2007-2010
> The Hilltop Institute
> University of Maryland Baltimore County
> 
> cinnie wrote:
> > greetings gurus
> > 
> > I am having trouble with the syntax of a query I'm trying to write.  Here is 
> > the situation, simpified to its essence:
> > C:/DB/A.mdb has tblNames with relevant fields CustID, CustName, CustEMail.
> > C:/DB/B.mdb has the same table and fields.
> > C:/DB/C.mdb also has the same table and fields.
> > 
> > Many of the names appear in 2 or 3 of the databases, but most names appear 
> > in only one of the three databases.
> > 
> > Here's what I am trying to do (so far without success)...
> > 
> > I want the values of CustID, CustName, CustEMail that are in A.mdb   
> > UNION
> > the values of  CustID, CustName, CustEMail that are in B.mdb.
> > Then I need to remove any doubles (same PK CustID) from the resulting 
> > recordset.
> > Finally, I need to EXCLUDE any of these remaining records that ALSO appear 
> > in C.mdb.
> > 
> > I would be SO greatful for help.   -  cinnie
> > 
> .
> 
0
Utf
2/13/2010 7:40:02 PM
In both cases, I changed "WHERE TableC.CustID is Not Null" 
to "WHERE TableC.CustID is Null".
-- 
cinnie


"John Spencer" wrote:

> If you have links in the A.mdb to the relevant table in B.Mdb and C.mdb then 
> the following should work to give you a unique list of CustID, CustName, and 
> CustEmail that are in either A or B and not in C.
> 
> SELECT A.CustID, A.CustName, A.CustEmail
> FROM TableA LEFT JOIN TableC
> ON TableA.CustID = TableC.CustID
> WHERE TableC.CustID is Not Null
> UNION
> SELECT B.CustID, B.CustName, B.CustEmail
> FROM TableB LEFT JOIN TableC
> ON TableB.CustID = TableC.CustID
> WHERE TableC.CustID is Not Null
> 
> If you want just one record per CustID and there are possible duplicates 
> records because CustName or CustEmail differs then you can use the UNION query 
> as the source for another query where you aggregate the data
> 
> SELECT CustID, First(CustName), First(CustEmail)
> FROM qUnionQuery
> GROUP BY CustID
> 
> IF you want the latter, you might change UNION to UNION ALL and see if that 
> returns the results faster or slower.
> 
> John Spencer
> Access MVP 2002-2005, 2007-2010
> The Hilltop Institute
> University of Maryland Baltimore County
> 
> cinnie wrote:
> > greetings gurus
> > 
> > I am having trouble with the syntax of a query I'm trying to write.  Here is 
> > the situation, simpified to its essence:
> > C:/DB/A.mdb has tblNames with relevant fields CustID, CustName, CustEMail.
> > C:/DB/B.mdb has the same table and fields.
> > C:/DB/C.mdb also has the same table and fields.
> > 
> > Many of the names appear in 2 or 3 of the databases, but most names appear 
> > in only one of the three databases.
> > 
> > Here's what I am trying to do (so far without success)...
> > 
> > I want the values of CustID, CustName, CustEMail that are in A.mdb   
> > UNION
> > the values of  CustID, CustName, CustEMail that are in B.mdb.
> > Then I need to remove any doubles (same PK CustID) from the resulting 
> > recordset.
> > Finally, I need to EXCLUDE any of these remaining records that ALSO appear 
> > in C.mdb.
> > 
> > I would be SO greatful for help.   -  cinnie
> > 
> .
> 
0
Utf
2/14/2010 11:30:02 PM
Of course.  My error.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

cinnie wrote:
> In both cases, I changed "WHERE TableC.CustID is Not Null" 
> to "WHERE TableC.CustID is Null".
0
John
2/15/2010 10:04:14 PM
Reply:

Similar Artilces:

Receipt Printer Help!!
Can a Verifone 250 credit card receipt printer be used with RMS as a cash receipt printer? If so, what cable connectors would be needed to do this. The only cable connector we have goes to the credit card terminal. Kelly Why would you want to? Very slow printer!!!! Get a Samsung erp-350 or a 270. Probibly have to have a custom cable. >-----Original Message----- >Can a Verifone 250 credit card receipt printer be used >with RMS as a cash receipt printer? If so, what cable >connectors would be needed to do this. The only cable >connector we have goes to the credit card ...

Suspicion of CListCtrl memory leak, Help !
I have a testing MFC DialogBase project which has only one control -- ListCtrl. When the app exit , i found that the memory is not free by the system by watch the System Performance dialog page. All that i do is within CListCDlg::OnTimer() func, show as bellow: < code snippet> void CListCDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CListCDlg) DDX_Control(pDX, IDC_LIST1, m_MyList); //}}AFX_DATA_MAP } void CListCDlg::OnTimer(UINT nIDEvent) { TCHAR sContent[ 128 ]; //I have not alloc any data from heap, all the data added to CListCtl is ...

Need with with 4125 RWW Not Working
SBS2008 Remote from Win 7 Pro and XP Pro clients I am having an issue with getting RWW to work in the SBS 2008 environment. Basically I can connect to the server via \remote from a off-site location but when I try and "Connect to a Computer" I get the following message. "The wizard cannot configure Remote Desktop Connection settings. Make sure that the client version of the Remote Desktop Protocol (RDP) 6.0 or later is installed on this computer." This also includes when I try and connect to the SBS 2008 server itself. At first I thought when this didn...

Calling Dex Procedures from SQL
Is there any way to call dex procs from SQL or VB code? Jed There is an undocumented and unsupported method of calling Dex code from VBA. However, I know of no method of calling Dexterity from SQL. Please email me if you want an example, just remove the online. from the address below. David Musgrave [MSFT] Senior Development Consultant MBS Services - Asia Pacific Microsoft Business Solutions http://www.microsoft.com/BusinessSolutions mailto:dmusgrav@online.microsoft.com Any views contained within are my personal views and not necessarily Microsoft Business Solutions policy. This p...

is SQL 2000 architecture different SQL Server 2005 / 2008 architecture?
Hi I have a book "inside SQL Server 2000" by Kalen Delaney, which I have been told is a good book. I am going backwards... reading about the sql server architecture in chapter 3 of the book. As I'm reading... I was wondering is it different SQL Server 2000 vs SQL Server 2005/2008? Also where can I find a book/or link that can give me more details about the internals on architecture? Thank you norm (normanchan@gmail.com) writes: > Hi I have a book "inside SQL Server 2000" by Kalen Delaney, which I > have been told is a good book. I am g...

VLOOKUP help. Im an Excel Newbie!!1
I have an Invoice worksheet which I must use VLOOKUP function to import data such as customer name, customer code, customer address, etc. My study sheets didn't explain how to use VLOOKUP for obtaining data from different files. Basically on the Invoice worksheet, in the cell under customer code use the VLOOKUP function to enter the customers name (from the table on the customers worksheet). In the cell under customers name use VLOOKUP to enter customers address, in the cell under customers address use VLOOKUP to enter suburb,state and postcode (from customer worksheet). Then I need to...

Help with database
I need to create a database that lists companies, with dates items done by, money paid, notes etc. Thats okay, but I need to retain the previous years records and start a new year off fresh. How would I do that? Jenni, It sounds like you have never created a database so I'm going to suggest you start here... Jeff Conrad's resources page... http://www.accessmvp.com/JConrad/accessjunkie/resources.html The Access Web resources page... http://www.mvps.org/access/resources/index.html A free tutorial written by Crystal (MS Access MVP)... http://allenbrowne.com/casu...

Aarrgghh!!! Can send external mail but not receive it
My customer has one Exchange Server with 2 domains - I'll call them 'companyA.co.uk' and 'companyB.net'. The users for CompanyA are the same people as the users for CompanyB. There is a requirement for these users to send and receive email (they use Outlook) from both their 'companyA.co.uk' and their 'companyB.net' addresses. I acheived this by configuring 2 user accounts per user in Active Directory and then giving one user full control of the other, and by giving one user permissions to view/send as etc on behalf of the other. This worked fine for over...

i need help
i signed into windows live again. i used to have this email several months ago without a problem and one day i tried to log in and it kept telling me i had the wrong password i tried to reset it with out any luck. what can i do to log back into POP3 again? Live.com Settings: Server names and ports: POP3 = pop3.live.com Port = 995 SMTP = smtp.live.com Port = 587 Checkboxes you need to check include: Server Tab: "My server requires authentication" (Click "Settings" button also and fill in "Log on Using" email address - *** bu...

HTML Help Context Sens. Help in Dialogs
Hey folks, I've been able to add context-sensitive HTML Help to an MFC dialog box, but there's an annoying behavior that I'm wondering if there's a workaround for (or if it's a bug). Version is VS2008 (not SP1 beta). If I click the "Help Tool" on a particular button that I've got mapped to an HTML file, the wrong control help ID gets sent to the OnHelpInfo(HELPINFO* pHelpInfo) handler. Visually, when running the dialog, there appears to be a "cursor" of sorts that highlights one button at a time (focus?), and this cursor seems to respond to...

Major help needed!!!!
Hello, Just came across this problem today. I have a spreadsheet I've been using for over 2 years that was originally created in excel 97. We are now working with excel 2003. The error that occurs is when I copy a cell in the existing spreadsheet to a cell in a new spreadsheet, the date changes by 4 years and 1 day. ex: 10/21/04 becomes 10/20/00. However, If I open a new spreadsheet and place a date in a cell, copy that date, open another new spreadsheet and paste the cell into it then the date does not change. I'm taking it that it's because of my original spreadsheet being d...

How can I group a set of documents needs to be opened repetatively
How can I group a set of documents needs to be opened repetatively? Hi Prithvi, You can open all the required documents and then choose File + Save WOrkspace. The next time you want them all open just open the Workspace. Judith -- Hope this helps "Prithvi" wrote: > How can I group a set of documents needs to be opened repetatively? ...

Formulas
I have a huge database that I need to add fields and build a couple of formulas for those fields. Right now I have 3 months worth of data that I need to be able to report trending on. Within those 3 months, I have loan data breaking out how many loans have closed for a multitude of reasons. I need to trend how many each month close for those reasons and what they are as a percentage of the overall total of loans for that month. Any suggestions? To see how many closed in each month with each reason, you could just do a query that summarizes the data. I don't know what yo...

Moving customizations from SQL 2k to SQL 2k5 CRM
This may be a non-issue but I wanted to check to see if anyone has done this and ran into issues. I have the XML customization files from our previous install of CRM 3.0 with SQL 2k database. I now want to import and publish these same customizations to CRM 3.0 on SQL 2k5. Has anyone done this or can point me to documentation that tells about the success or issues for doing this? Thanks. On 7 Feb., 06:35, Chris Treanor <ChrisTrea...@discussions.microsoft.com> wrote: > This may be a non-issue but I wanted to check to see if anyone has done this > and ran into issues. > &...

Help! #2
Hello, i have to program an application which should do the following 1. Receive the binary data on 2 channels. 2. each channel will store their corresponding data to a common file (july4.text) (each day 1 file will be created) 3. Each day the data received will be close to 30 MB of raw data (thought SQL will not be appropriate for this) 4. The data which is stored in a file will have around 5000 parameters.(ie: name,age,temperature,etc,etc) 5. MFC application to read/parse the specified data(queried like june20th to july2nd) and display it in graphical manner.(MS Chart?) 6. The parameters ...

Subquery help
I am trying to set a value in a variable and am getting the error "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression." The set line it fails on is below. How can I work around this? Thanks. SET @FedWHAllow = (SELECT FedWHAllow FROM PayFreq WHERE PayFrequency = (SELECT PayFrequency FROM BranchPayrollGroups WHERE PayrollGroup = @PayrollGroup)); -- David You can change the WHERE clause predicate in the subquery to guarantee only a single row is returne...

Need to add check transactions to Microsoft Money using OFX file (not bank statements)
Does anybody have an example of an OFX file that imports check transactions into Microsoft Money? I need to simulate the manual input of checks. Dut to problems in our accounting software, it's best to enter transactions in our accounting system and rekey them into MS-Money. I found some "statement" files but I am thinking this isn't what I need to do????? I appreciate the depth and functionality of ofx vs. qif but I am finding it difficult to find ofx examples since they all appear to be produced by large companies (i.e. banks and financial companies) Any help wo...

user account disabled. need to redirect his e-mail
Hi, I have a situation: User left the company. I disabled his AD account. His boss asking to redirect this user new incoming e-mail to other user. Can you suggest an appropriate solution. Do I have to activate his account and just change a password or I can keep this account blocked. Thanks. Michael. On Sat, 7 Jan 2006 18:55:02 -0800, "MLA!" <MLA@discussions.microsoft.com> wrote: >Hi, >I have a situation: > >User left the company. >I disabled his AD account. >His boss asking to redirect this user new incoming e-mail to other user. > >Can you sugge...

Free & Busy Data messed up.. Plz Help!!
We have exchange v5.5. Recently one of the exchange admins was in the public folders messing around with permissions. He said he didn't change anything but something had to have changed because now all free and busy data, public address book, tasks, notes, etc are not accessible to new users. Any time we create a new email account they can't view there calendar (says it doesn't exist), nothing shows up in the global address list. Anytime they receive an email to accept a meeting it says unable to open item. I've done the usual things like reset the server. I loo...

Help needed urgently
Hi, Im trying to check that one row of data satifies a criteria, then if it does it counts an entry in another column adjescent to it. Example: - Column A - Column B Blay - Y Blay - N Blay - Y Chop - N Chop - N High - Y What i would be asking (of a much bigger table) is If Column A = Blaydon and then column B (same row) = Y, then count. In this example I would want 2 returned as the answer. Is this possible? Thanks -- Andy Try one of these... Use cells to hold the criteria: D2 = Blaydon E2 = Y If you're using Excel 2007 or later: =COUNTIFS(A2:A7,...

CRM 3.0 Install Error with SQL Reporting Services and SQL 2005
Hi, Doing a CRM 3.0 Server installation. During the last page of the install wizard (or what I assume is the last page) when I goes through and does verification I get a red X next to SQL Reporting Services. The message I receive when I look at the details is: ***** The specified path is not a metabase path. Parameter name: path ***** Now SRS is installed and working. I put in the URL: http://<servername>/reportserver and every other variation on that I can find. Thoughts? Alan try http://servername/reports also assuming you did not use ssl... =======================...

SQL 'for xml' and C# example??
I'm missing some piece of the puzzle. I'm using 'for xml' type queries from SQL2K - and now trying to change the front-end from ADO to C#, I can't quite figure it out.. It seems that I could use an XmlReader.. and somehow use that instead of a DataReader.. but that didn't work.. I tried using a DataReader and get the byte array - but that wasn't right. SQL returns formatted XML, I need to load that XML into an XmlDocument somehow without ANY molestation of that dom. Any ideas? Examples? Missing links???? thanks THANKS!! I've been looking for the answer to ...

Vlookup help #2
I have two worksheets. Sheet 1 contains a number in column A and a name in column C. On Sheet 2 I put my data from a csv file. What I would like to do is vlookup Sheet 1 column C from the information on Sheet 2 and return the number in column A that is associated with the name in column C. Ex. Sheet 1 Sheet 2 A B C A B 33 N6-270-15 N6-270-75 35 34 N6-270-30 N...

SFO help
I have a quick question. My client's SFO button's wont install, and generally, their SFO installation is unstable. Given that we're hosting Exchange and CRM for the client and they're accessing our systems via VPN, does SFO work when their systems are not part of the domain that we've set up for them locally on our premises? Thanks!! Chris ...

sql summarizing help
Hi All, Given: table1 --------- id, cdate, weeksago, amount, typeid, timeclose 496, 2010-02-11, 0, 450, 3, 1 490, 2010-02-01, 1, 200, 4, 1 491, 2010-02-01, 1, 350, 2, 2 493, 2010-02-01, 1, 500, 5, 1 489, 2010-01-21, 3, 150, 2, 1 136, 2010-01-12, 4, 500, 3, 2 137, 2010-01-12, 4, 100, 3, 1 138, 2010-01-12, 4, 500, 2, 1 1. i'm trying to create a sql that will give me a summary resultset grouped by weeksago. 2. i want to sum the columns and get counts based on typeid. 3. avg of timeclose here's the sql i have: select weeksago, , (sum(timeClose)/(count(timeclo...