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 > Joining 3 tables with natural join

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-10, 16:06
boxden boxden is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
Joining 3 tables with natural join

Hello everybody.

Take this database schema:
Classes(class, type, country, numGuns, bore, displacement)
Ships(name, class, launched)
Battles(name, date)
Outcomes(ship, battle, result)

Find for each class the year in which the last ship of that class was sunk.

Does following work when I try to natural join Classes Ships and Outcomes?

SELECT Classes.class, MIN(date)
FROM Classes NATURAL JOIN Ships NATURAL JOIN Outcomes
WHERE result = 'sunk'
GROUP BY Classes.class

Or would I have to do something as

FROM Classes NATURAL JOIN Ships CS, CS NATURAL JOIN Outcomes CSO

And can you give tuple variables to a join, like CS and CSO?

Kind regards
Reply With Quote
  #2 (permalink)  
Old 03-24-10, 16:08
boxden boxden is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
I apologise, should've made this thread in the SQL forums.
Reply With Quote
  #3 (permalink)  
Old 03-24-10, 19:34
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
It appears that you've got a very early assignment from a class. Probably your first or second class session would be my guess. Experiment a bit, you don't need to be afraid of breaking things while doing a SELECT!

Give it a shot. If you have questions about your results, show us what you tried and what result you got. We'll be glad to help, but we won't do your homework for you (if we appear to do your homework for you, be VERY nervous!).

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #4 (permalink)  
Old 03-24-10, 20:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by boxden View Post
Ships(name, class, launched)
Battles(name, date)
unless the homework assignment specifically requires that you must use NATURAL joins, i would stay well and truly clear of them

if you should ever accidentally put the Ships and Battles tables into the same query with NATURAL joins, you might be surprised (if that's the word) at the results you get (hint: probably none)

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-25-10, 10:05
boxden boxden is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
@ Pat Phelan, I don't really know how to test queries lol What is a free way (accept for MS Access) to create a database schema and use SQL(querying and updating) ?

@ r937 Yep sorry my bad lol it was no homework assignment, my book is just filled with schema's of ships so I wanted to construct a query so I could ask my question concerning 3 nat joins but I forgot Battles name is the name of the battle :-) Bad example. My actual question is...

Can you join 3 relations R,S,T in a for clause like

R NATURAL JOIN S NATURAL JOIN T
or would you have to do something like
R NATURAL JOIN S, S NATURAL JOIN T

I know this would be easy to test if I knew how as I stated in the beginning of this reply.
I acctually had my computer science exam of introduction to database technologies today and it went very well. Whenever something as joining 3 relations occured, I just joined them in the WHERE clause.

Kind regards
Reply With Quote
  #6 (permalink)  
Old 03-25-10, 10:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by boxden View Post
I know this would be easy to test if I knew how as I stated in the beginning of this reply.
most of the more common database systems offer a free version

probably the easiest to set up and get started with is mysql, but you need to pick one for yourself

google is yoiur friend to find the download pages for whichever system you choose

and do heed my advice -- stay well away from NATURAL joins
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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