|
 |
|
 |
11-13-2005, 08:00 PM
|
#1 (permalink)
|
|
Registered User
Join Date: Nov 2005
Posts: 3
|
sql / php
In a paractice exam, the question is:
select fname,lname
from student
where student_id in
(select sid
from registration
where iid in
(select instructor_id
from faculty
where fname="dumbledore"))
restate the query as a join operation in sql.
VERY new, would like to see how a pro does it. Knowing nothing about joins yet, here is my try:
select student.fname,student.lname,student.student_id
registration.sid,registration.iid,
faculty.instructor_id, faculty.fname
from student,
faculty join registration on
faculty.instructor_id = registration.iid
join student on
student.student_id = registration.sid
where faculty.fname="dumbledore"
please tell me what is wrong with this and how to fix it.
~elohmrow
|
|
|
11-14-2005, 12:59 PM
|
#2 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
Well as a general style thing, I'd say you should capitalize your sql commands to make them distinct, e.g. "SELECT field2 FROM table1 WHERE id = 7" versus "select field2 from table1 where id = 7" Also I'm pretty sure you don't need to explicitly call the join command to perform a join, rather it automatically joins when you select from multiple tables.
I think a proper join would be "SELECT student.name, student.grade, instrucor.name FROM student, instructor WHERE instructor.id = student.instructor_id"
__________________
Stop intellectual property from infringing on me
|
|
|
11-14-2005, 01:50 PM
|
#3 (permalink)
|
|
Registered User
Join Date: Nov 2005
Posts: 3
|
Thank you for the reply.
The first snippet I provided is a join, but the practice exam wants instead of the join provided, for us to explicitly say "JOIN" in there. So the point is to convert what was given to an equivalent statement using explicit JOIN statements.
|
|
|
11-14-2005, 06:49 PM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
fun, 3 tables
Code:
SELECT student.fname, student.lname from student
LEFT JOIN registration on student.sid=registration.sid
LEFT JOIN faculty on registration.iid=faculty.instructor_id
WHERE faculty.fname='dumbledore'
|
|
|
11-14-2005, 06:55 PM
|
#5 (permalink)
|
|
Registered User
Join Date: Nov 2005
Posts: 3
|
much obliged, hombre 
|
|
|
11-15-2005, 11:44 AM
|
#6 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
I don't understand the middle finger smiley...
__________________
Stop intellectual property from infringing on me
|
|
|
11-15-2005, 01:30 PM
|
#7 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
|
We've had this discussion befor, some claim it to be a "thumbs up" smiley, others think it's a "flip you the bird" smiley...
|
|
|
11-15-2005, 01:45 PM
|
#8 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
Oh, I guess I can see that.
__________________
Stop intellectual property from infringing on me
|
|
|
11-15-2005, 06:21 PM
|
#9 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
lol, i forgot about it .. i always take it as people being a smart ass giving me the bird =)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 10:48 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|