Joining four tables..need help [message #650393] |
Sun, 24 April 2016 04:41 |
|
dbJuniorAdmin
Messages: 6 Registered: April 2016
|
Junior Member |
|
|
Hi
How can I accomplish the following?
Q. Find the full names of applicants, titles of positions they applied for in year 1999 and the names of employers from Sydney who offer the positions.
Tables are: applicant, positions, applies, employer. Applies table has only primary keys of position and applicant
I tried natural join but it outputs "no rows selected"
Pls help.
|
|
|
Re: Joining four tables..need help [message #650394 is a reply to message #650393] |
Sun, 24 April 2016 04:44 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
What do you expect from us with no table description, no relational model, no relationship between these tables, in short nothing?
Show us the tables, show us what you tried.
Note that "natural join" is a good starting point to program bugs. Better explicitly express the join conditions.
[Updated on: Sun, 24 April 2016 04:45] Report message to a moderator
|
|
|
|
|
|
|
Re: Joining four tables..need help [message #650399 is a reply to message #650395] |
Sun, 24 April 2016 04:54 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Think about what natural join is doing: joining tables on columns with the same name. Then look at your tables. You have several columns with the same name, how many of them are meaningful join columns?
|
|
|
|
|
Re: Joining four tables..need help [message #650404 is a reply to message #650403] |
Sun, 24 April 2016 06:23 |
|
dbJuniorAdmin
Messages: 6 Registered: April 2016
|
Junior Member |
|
|
I think I did it, but I think it was worth posting here somewhat
as no one really gave me a solution
select fname,lname,title,ename from (select title,city,ename from position natural join employer) natural join applicant natural join applies where (extract(year from appdate)='1999' and city='Sydney');
FNAME LNAME TITLE ENAME
--------------- --------------- -------------------- --------------------------------
John Spiderman Professor University of New South Wales
John Spiderman Lecturer University of New South Wales
Margaret Finch Professor University of New South Wales
Margaret Finch Lecturer University of New South Wales
John Spiderman Associate Professor University of Technology, Sydney
John Spiderman Senior Lecturer University of Technology, Sydney
Margaret Finch Associate Professor University of Technology, Sydney
Margaret Finch Senior Lecturer University of Technology, Sydney
8 rows selected.
|
|
|
Re: Joining four tables..need help [message #650405 is a reply to message #650404] |
Sun, 24 April 2016 06:32 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
What you have done is devised a work around for the limitation of NATURAL JOIN, by projecting only a subset of the columns in EMPLOYER. It works in this case but what if you wanted to include the EMAIL columns in your output? You teacher will, I suppose, have to give you a positive mark, but it may be the lowest possible.
|
|
|
Re: Joining four tables..need help [message #650483 is a reply to message #650393] |
Tue, 26 April 2016 07:25 |
martijn
Messages: 286 Registered: December 2006 Location: Netherlands
|
Senior Member |
|
|
Maybe a bit bold question but: do you know what a join actually is?
I have the distinct feeling that you do not understand the idea of joins.
I suggest learning about joins, for example from here
|
|
|
Re: Joining four tables..need help [message #650487 is a reply to message #650483] |
Tue, 26 April 2016 12:11 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
As a professional software designer/developer for 30 years I can tell you to NEVER use natural joins in any production code. It WILL break eventually. Specify your join conditions. In my mind it shouldn't even be allowed in the language.
|
|
|