Solved

Joining Three table using SQL

Posted on 2000-03-28
9
170 Views
Last Modified: 2010-05-02
How to join three tables using SQL

joining loan and customer tables using customer_No
 
joining loan and payment tables using
loan_No
 
 Text1.text = Payment_No
 text2.text =loan_No
 Text3.text = Customer_No


 Private sub find_click()
 
  dtpayment.recordsource = "select * from payment where Payment_No = '" & text1.text & "'"
 
  dtpayment.refresh

  dtloan.recordsource = "select* from loan where Loan_No= '" & text2.text & "'"

  dtloan.refresh

 dtcustomer.recordsource = "select * from customer where customer_No = '" & text3.text & "'"

   dtcustomer.refresh

  end sub

 How this doesn't work

  please help

  abraham
0
Comment
Question by:abrahamling
9 Comments
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
SELECT
FROM Payment INNER JOIN (Loan INNER JOIN CustomerTable ON Loan.[Customer No] = CustomerTable.[Customer No]) ON Payment.[Customer No] = Loan.[Customer No];
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
What is your exact problem?
The only thing i can see is that you are querying 3 times the database and this could be done in 1 throw (see caraf_g's statement), and that in your 2nd statement there is no space between SELECT and *.
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 100 total points
Comment Utility
Tip: whenever you need to do complicated stuff like this in SQL you can go into Access, create a database with tables similar to your own and create a query with the handy drag & drop facilities provided. Finally, look at the sql view.

I made a small mistake in the query above in that I joined everything up on customer no.

Better:

SELECT
FROM (CustomerTable INNER JOIN Loan ON CustomerTable.[Customer No] = Loan.[Customer No]) INNER JOIN Payment ON Loan.[Loan No] = Payment.[Loan No];


And just use this as the record source for a single query.
0
 
LVL 1

Expert Comment

by:prax_n
Comment Utility
If u could explain u r problem properly ...I could explain something .. i did not upderstand u r prob..
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Expert Comment

by:simonstre
Comment Utility
the inner joins are the best solution, but here's another one :-)


SELECT * FROM LOAN, PAYMENT, CUSTOMER WHERE [LOAN].LOAN_NO = [PAYMENT].LOAN_NO
  AND [CUSTOMER].CUSTOMER_NO =   [LOAN].CUSTOMER_NO
0
 

Author Comment

by:abrahamling
Comment Utility
Thanks you caraf_g's

 
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Thank you? So why did you give me a "C"?

If my answer was in any way unsatisfactory, I would have preferred it if you had asked further questions, and I would have been happy to resolve outstanding problems with you. A "C" looks bad in my profile... :-(
0
 

Author Comment

by:abrahamling
Comment Utility
Caraf_q, thanks you for your help,

  I really mean it. sorry for giving u

  a "C". but i promise, next time, i

 will definitely give a excellent Grade.
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Hey, no problem! Thanks for clearing that up ;-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now