Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-13-2005, 08:00 PM   #1 (permalink)
elohmrow
Registered User
 
Join Date: Nov 2005
Posts: 3
elohmrow is on a distinguished road
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
elohmrow is offline   Reply With Quote
Old 11-14-2005, 12:59 PM   #2 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
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
teknomage1 is offline   Reply With Quote
Old 11-14-2005, 01:50 PM   #3 (permalink)
elohmrow
Registered User
 
Join Date: Nov 2005
Posts: 3
elohmrow is on a distinguished road
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.
elohmrow is offline   Reply With Quote
Old 11-14-2005, 06:49 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
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'
sde is offline   Reply With Quote
Old 11-14-2005, 06:55 PM   #5 (permalink)
elohmrow
Registered User
 
Join Date: Nov 2005
Posts: 3
elohmrow is on a distinguished road
much obliged, hombre
elohmrow is offline   Reply With Quote
Old 11-15-2005, 11:44 AM   #6 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
I don't understand the middle finger smiley...
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 11-15-2005, 01:30 PM   #7 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
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...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 11-15-2005, 01:45 PM   #8 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Oh, I guess I can see that.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 11-15-2005, 06:21 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
lol, i forgot about it .. i always take it as people being a smart ass giving me the bird =)
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 5.0.4 and 4.3.11 Released sde Code Newbie News 0 04-20-2005 10:56 AM
PHP vs .NET Redline Lounge 1 11-24-2004 06:10 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM
Linux, Php, and Sql Oh My... JeC Linux / BSD / OS X 9 02-28-2003 04:26 AM
loading sql schema from php sde PHP 7 12-11-2002 06:57 PM


All times are GMT -8. The time now is 10:48 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting