?
Solved

How would you join another table to an existing query?

Posted on 2011-02-25
7
Medium Priority
?
348 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 2000 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

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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 …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Suggested Courses

743 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