Results 1 to 5 of 5

Thread: sql query

  1. #1
    Join Date
    Jan 2004
    Posts
    30

    Unanswered: sql query

    I want to join a table to the answer of a join i.e.

    Table 1, 2 and 3....

    1st I join Table 2 and 3 where ID = 4 like a normal join (no probs : )) and return *.Table 2

    next i want to join Table 1 with the answer of the 1st join...how do I do that????

  2. #2
    Join Date
    Feb 2004
    Posts
    492
    I'm not sure if I understand what you want, but why not expand your current join-statement?

    select *
    from table1 t1
    inner join table2 t2 on (...)
    inner join table3 t3 on (...)
    ...

  3. #3
    Join Date
    Jan 2004
    Posts
    30
    soz i dont fink my thread made much sense....

    This is would I want to do

    1st table = customer (includes customerID)
    2nd table = contract ( includes contract ID, customer ID)
    3rd table = car (includes carReg and contract ID)

    The user inputs a car reg...from that I want to return the customer details of that car reg....

    so I need to join car and contract to get the contract ID of that car reg and then use this contract ID in customer table to return the correct record!!!

    I cant seem to get my head round it!!!

  4. #4
    Join Date
    Jan 2004
    Posts
    30
    soz i dont fink my thread made much sense....

    This is would I want to do

    1st table = customer (includes customerID)
    2nd table = contract ( includes contract ID, customer ID)
    3rd table = car (includes carReg and contract ID)

    The user inputs a car reg...from that I want to return the customer details of that car reg....

    so I need to join car and contract to get the contract ID of that car reg and then use this contract ID in customer table to return the correct record!!!

    I cant seem to get my head round it!!!

  5. #5
    Join Date
    Aug 2004
    Posts
    10
    try this:

    create view v1 as

    select cu.*, ca.* from customer cu
    inner join contract co on cu.customerid = co.customerid
    inner join car ca on ca.contractid = co.contractid
    go

    declare @carReg int
    set @carReg = 1 -- input from user
    select * from v1 where carReg = @carReg
    go

    hth,
    Cristian Babu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •