If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > need help with multi-table query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-04-07, 11:43
amy7756 amy7756 is offline
Registered User
 
Join Date: Jul 2006
Posts: 28
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
Reply With Quote
  #2 (permalink)  
Old 01-04-07, 12:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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/

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-05-07, 14:08
amy7756 amy7756 is offline
Registered User
 
Join Date: Jul 2006
Posts: 28
Thanks so much - that's exactly what I was looking for!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On