Results 1 to 10 of 10

Thread: Subqueries

  1. #1
    Join Date
    Oct 2008
    Posts
    24

    Unanswered: Subqueries

    How can I use a subquery to pull data from across 4 tables? For instance,

    table1........ table2...........table3...........table4
    pk1.............fk1...............pk2............. ..pk2
    ..................fk2



    I am pulling data from table 4, table 1 and table3. I was able to do it without a subquery, but what if I wanted to use a subquery?
    Last edited by Datanalysis; 11-13-09 at 15:42. Reason: format

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    I lack the patience for guessing games today. Post some actual code, please.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd prefer a "real world" explanation. I can't begin to guess what Datanalysis had in mind.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by Datanalysis View Post
    I am pulling data from table 4, table 1 and table3. I was able to do it without a subquery, but what if I wanted to use a subquery?

    If you want to "pull" data (I'm guessing in a SELECT as part of a result set) using a sub query, then the answer would be no, you can't do that.

    Then again, your definition of what a "sub-query" is might be completely different than we understand it to be...

    The only thing I pulled lately...ummm never mind
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Oct 2008
    Posts
    24
    Sorry I should of been more detailed on the structure of the tables.

    table1..............table2.................table3. .....................table4
    pk_driver_id......fk_driver_id...........pk_covehi cle_Id........travellog_id
    lastname..........fk_covehicle_id......vehicle_Num ber.........fk_covehicle_id


    I cant get the query to work, it would need gather travel_log_id, Vehicle-number
    and the subquery would need to gather lastname from table1. Thanks.

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    post the actual query please
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    In what way is that more detailed?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  8. #8
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716
    C'mon you guys...do a little MINDREADING, won't you? It's obvious what he is after.

    I would answer, but I think you guys should work on it a while before I just give it over to y'all.
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

  9. #9
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Sorry Paul, this one is outta my league. I'll leave it to you big fella!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  10. #10
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Datanalysis View Post
    I was able to do it without a subquery, but what if I wanted to use a subquery?
    that's nuts

    if you can do it without a subquery, the problem is solved already

    or is this a homework assignment?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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