Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004

    Unanswered: SQL Select stmt using multiple tables

    i have a very simple question,
    when using the select stmts, i usually just use
    2 tables.

    from author, book
    where = book.authorid;

    can you guys give me a very basic select stmts
    using three, four, five, etc tables.....
    let us assume that only AND will be used and
    only table values compared with another table
    values will be used... (ex. this will not be used: = 111)

    my idea is somthing like is, i'm not sure if this is correct

    3 tables
    from author, book, library
    where = book.authorid AND = library.auhorid;

    *** i will use the primary key of the 1st table to join to the 3rd table.

    4 tables
    from author, book, library
    where = book.authorid AND = librarian.libraryid;

    *** 1st table is join to 2nd table and 3rd table is joined to 4th table.

    5 tables
    I HVE NO IDEA...

    PLEASE HELP ME!!!!!!!!!!!!

  2. #2
    Join Date
    Jan 2004

    Yea you have the idea on multiple joins - you just use AND and the next join. But for us to answer the question (and I dont really see one here) we would have to understand how your database is set up.

    Joins are joins - for every extra table you add, it should have a join to one of the other tables, or you need to go back to the drawing board and start normalizing some more!

    I mean if you just an example here goes - it wont mean anything but..
    select a.col1, b.col1, c.col1. d.col1
    from a,b,c,d
    where = and
    = and
             d.col2 = c.col2
    Since I havent used the emp/dept tables in ages, I can't think of a good example using more than 2 of those tables.
    Last edited by ss659; 12-13-04 at 22:13.
    Oracle OCPI (Certified Practicing Idiot)

  3. #3
    Join Date
    Oct 2004
    ok, thanks for the help.

Posting Permissions

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