Solved

How would you join another table to an existing query?

Posted on 2011-02-25
7
335 Views
Last Modified: 2012-05-11
I am developing and Access 2003 application using an MDB type file

How would you join another table named tblBanksRev to the follwing query as follows?

SELECT tblBanks.*, tblDates.dtRec, tblOpenItems.*
FROM tblDates,
tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
WHERE tblOpenItems.t In ("A","D","E");

ADD the following table to the Query:

tblBanksRev.[BRS #]  = tblBanks.[Bank Code]
0
Comment
Question by:zimmer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 5

Expert Comment

by:MikkelAStrojek
ID: 34982319
SELECT tblBanks.*, tblDates.dtRec, tblOpenItems.*
FROM tblDates, tblBanks
INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
INNER JOIN tblBanksRev ON tblBanksRev.[Bank Code]=tblBanks .BankWHERE tblOpenItems.t In ("A","D","E");

The bold highlighted depends on what the tables have in common

0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 34982333
Like this
SELECT tblBanks.*, tblDates.dtRec, tblOpenItems.*
FROM tblDates,  
tblBanks 
INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
INNER JOIN tblBanksRev ON tblBanksRev.[BRS #]  = tblBanks.[Bank Code]
WHERE tblOpenItems.t In ("A","D","E");

Open in new window

0
 
LVL 6

Expert Comment

by:AkAlan
ID: 34982344
SELECT tblBanks.*, tblDates.dtRec, tblOpenItems.*
FROM tblDates,
tblBanks
INNER JOIN tblOpenItems ON tblBanks.[Bank Code] = tblOpenItems.Bank
INNER JOIN tblBanksRev ON tblBanksRev.[BRS #]  = tblBanks.[Bank Code]
WHERE tblOpenItems.t In ("A","D","E");

This will only return records if there are records in tblBanksRev where the [BRS #] from tblBanksRev  matches [Bank Code] tblBanks

If you want All the records from tblBanks and any that have related records in tblBanksRev then you need to join it with a LEFT OUTER JOIN like this


SELECT tblBanks.*, tblDates.dtRec, tblOpenItems.*
FROM tblDates,
tblBanks
INNER JOIN tblOpenItems ON tblBanks.[Bank Code] = tblOpenItems.Bank
LEFT OUTER JOIN tblBanksRev ON tblBanksRev.[BRS #]  = tblBanks.[Bank Code]
WHERE tblOpenItems.t In ("A","D","E");

0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:zimmer9
ID: 34982988
SELECT tblBanks.*, tblDates.dtRec, tblOpenItems.*
FROM tblDates,
tblBanks
INNER JOIN tblOpenItems ON tblBanks.[Bank Code] = tblOpenItems.Bank
LEFT OUTER JOIN tblBanksRev ON tblBanksRev.[BRS #]  = tblBanks.[Bank Code]
WHERE tblOpenItems.t In ("A","D","E");

The above statement causes the following error:

Syntax error (missing operator) in query expression
'tblBanks.[Bank Code] = tblOpenItems.Bank
Left outer join tblBanksRev.[BRS #] = tblBanks.[Bank Code]'.

However, if I leave out the following LEFT OUTER JOIN statement from the query, then it works fine:

LEFT OUTER JOIN tblBanksRev ON tblBanksRev.[BRS #]  = tblBanks.[Bank Code]
0
 

Author Comment

by:zimmer9
ID: 34983090
Let me restate the error:

Syntax error (missing operator) in query expression
'tblBanks.[Bank Code] = tblOpenItems.Bank
LEFT OUTER JOIN tblBanksRev on
tblBanksRev.[BRS #] = tblBanks.[Bank Code]'.

0
 

Author Comment

by:zimmer9
ID: 34983165
If I use the following query:

SELECT tblBanks.*, tblDates.dtRec, tblOpenItems.*
FROM tblDates,  
tblBanks
INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
INNER JOIN tblBanksRev ON tblBanksRev.[BRS #]  = tblBanks.[Bank Code]
WHERE tblOpenItems.t In ("A","D","E");

then the error is very similar as follows:

Syntax error (missing operator) in query expression
'tblBanks.[Bank Code] = tblOpenItems.Bank
INNER JOIN tblBanksRev ON
tblBanksRev.[BRS #] = tblBanks.[Bank Code]'.



0
 
LVL 6

Accepted Solution

by:
AkAlan earned 500 total points
ID: 34983964
Your statement is definately not correct. You are trying to select all records from tblBanks, one column from tblDates (dtRec) and all from tblOpenItems

you then have FROM tblDates,tblBanks. That is a problem, you don't seperate the tables with a comma, you do it with joins
So you need a join with tblBanks

SELECT tblBanks.*, tblDates.dtRec, tblOpenItems.*

FROM tblDates

INNER JOIN tblBanks ON tblBanks.[SomeKeyGoesHere] = tblDates.[SomeKeyGoesHere]
INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
INNER JOIN tblBanksRev ON tblBanksRev.[BRS #]  = tblBanks.[Bank Code]
WHERE tblOpenItems.t In ("A","D","E");

Without knowing the table schema, there is no way for me to know which keys to join on.

I think you really need to study up on joins to understand the concept. http://www.w3schools.com/sql/default.asp has great free tutorials.




0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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