Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2006
    Posts
    28

    Unanswered: need help with multi-table query

    Hey All!

    I'm kind of a newbie at sql, and I need some help!

    I have 3 tables:

    servers table:
    server_name id host
    =========== == ====
    PRODDB 14 sol1
    TESTDB 22 sol2

    srv_db table:
    id db_name data_size log_size
    == ======= ========= ========
    14 stocks 5000 400
    22 stocks 5000 400
    14 bonds 2500 300
    14 options 2500 300

    backup_control table:
    id db_name batch last_dump
    == ======= ===== =========
    14 stocks morning 7/7/2006 7:00am
    14 stocks evening 7/7/2006 6:00pm
    22 stocks weekend 7/1/2006 8:00am
    14 bonds evening 7/7/2006 6:12pm



    I want to get the following report output:

    server_name database batch last_dump
    =========== ======== ===== =========
    PRODDB stocks morning 7/7/2006 7:00am
    PRODDB stocks evening 7/7/2006 6:00pm
    PRODDB bonds evening 7/7/2006 6:12pm
    PRODDB options NULL NULL
    TESTDB stocks weekend 7/1/2006 8:00am


    Also, can anyone point me to some good books and/or online tutorials WITH EXERCISES that might help me with queries that involve more than two tables?

    Thanks in Advance,

    Amy

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select s.server_name
         , sdb.db_name as database
         , bc.batch
         , bc,last_dump
      from servers as s
    left outer
      join srv_db as sdb
        on sdb.id = s.id
    left outer
      join backup_control as bc
        on bc.id = sdb.id
       and bc.db_name = sdb.db_name
    tutorials with exercises: http://sqlzoo.net/

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2006
    Posts
    28
    Thanks so much - that's exactly what I was looking for!

Posting Permissions

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