How can I conditionally join result sets from (3) tables based on common criteria?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • David Stellato
    New Member
    • Dec 2010
    • 1

    How can I conditionally join result sets from (3) tables based on common criteria?

    I have three tables that all have "loan" in common.

    Property
    Investorloans
    Loans

    I used the following statements to pull all the loans for the investorid (03, 04, 06, 10) by matching the loan number(s) from each table.

    I also want to join the information from the property file to the result set (again, "loan" is the common record match".

    SELECT investorloans.i nvestorid, investorloans.l oan, loans.*
    FROM investorloans
    FULL JOIN loans
    ON investorloans.l oan=loans.loan
    WHERE investorloans.i nvestorid in("03","04", "06", "10")
    order by investorid asc


    I am NOT a skilled programmer so sorry for asking something that might be so simple.

    One last piece of information. I could join the property table and the loans table by joining them based on the loan number - BUT, in the above problem, I only want the loans by the set of investors (i.e 3,5,5,10). That might make my problem more clear - the way I do it now is manually and time intensive by running multiple queries and retrieving the loan numbers and then having to paste them into a conditional statement and I know there is a better way if I knew what I was doing :-)

    Thanks!!
    Last edited by David Stellato; Dec 8 '10, 08:53 PM. Reason: Adding additional information
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Not sure I understand the problem but what is wrong with this
    Code:
    SELECT investorloans.investorid, investorloans.loan, loans.*
    FROM investorloans
    FULL JOIN loans
    ON investorloans.loan=loans.loan
    JOIN property
    ON investorloans.loan=property.loan
    WHERE investorloans.investorid in("03","04", "06", "10")
    order by investorid asc

    Comment

    Working...