Solved

Joining Three table using SQL

Posted on 2000-03-28
9
193 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
ID: 2663819
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]
ID: 2663836
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
ID: 2663929
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Expert Comment

by:prax_n
ID: 2664859
If u could explain u r problem properly ...I could explain something .. i did not upderstand u r prob..
0
 
LVL 1

Expert Comment

by:simonstre
ID: 2665046
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
ID: 2665443
Thanks you caraf_g's

 
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2668176
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
ID: 2672538
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
ID: 2672567
Hey, no problem! Thanks for clearing that up ;-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 57
Updates not working for MS Windows 7 12 168
How to compare ms sql hashbytes results within vb6 5 77
TT Auto Dashboard 13 92
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

825 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