| |
|
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.
|
 |

09-29-03, 03:54
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
Query in SQL
|
|
Greetings
I'm brand new in using SQL , so I wish to get help here  .
how to find all students names who had taken a course from each professor outside the CS Department ??? 
|
Last edited by SAl; 09-29-03 at 14:08.
|

09-30-03, 05:58
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
|
|

09-30-03, 06:22
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
|
|
sounds like homework
what's your best attempt so far?
rudy
|
|

09-30-03, 12:46
|
|
Registered User
|
|
Join Date: Apr 2003
Location: Columbia, SC
Posts: 7
|
|
What have you got so far? What is your train of thought?
|
|

10-05-03, 06:08
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
This what I got ..
SELECT studid
FROM Transcript, Teaching
WHERE Transcript.crscode = Teaching.crscode And ( SELECT id FROM professor, teaching WHERE professor.id = Teaching.profid AND professor.dept <> 'CS')
??? 
|
Last edited by SAl; 10-06-03 at 02:39.
|

10-06-03, 02:42
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
Here is another attempt :
Select T.Crscode,Trans.stdid.P.Id
From professor p , Teaching T, Transcript Tans
Where p.Iddept <> 'CS'
|
|

10-06-03, 07:48
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
you need to be a bit more careful in your typing -- sql, like other languages, is very unforgiving about typos
you have a period between Trans.stdid and P.Id in the SELECT clause, and it should be a comma
also, you alias the Transcript table to Tans but then use Trans in the SELECT list
you said the problem called for student names, so you still need to join to the student table, and then use only SELECT DISTINCT student.name because the same student will take multiple classes from professors that aren't 'CS" but you want each student name to show up only once
|
|

10-08-03, 07:09
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
Hi Rudy ,
Thanx a lot for your notes
Here is My correction :
SELECT DISTINCT s.name
From Student S,
Where
( Select T.Crscode, Trans.stdid, P.Id
From professor p , Teaching T, Transcript Trans
Where p.Iddept <> 'CS'
)
Am I right now ???
|
|

10-08-03, 07:23
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
nope, even more diligence is required
there's a comma in front of WHERE
the subquery inside the parentheses will return an entire result set of rows, and this cannot be a condition of WHERE
you need to join the student table to the other tables
rudy
|
|

10-08-03, 07:38
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
OK
SELECT DISTINCT s.name
From Student S
Where
( Select T.Crscode, Trans.stdid, P.Id
From professor p , Teaching T, Transcript Trans
Where p.Iddept <> 'CS'
)
What about the Join ?? How can I use it here ??
|
|

10-08-03, 07:43
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
you still have that syntax problem in the WHERE clause
the WHERE clause needs to have one or more conditions that evealuate true or false
a subselect consisting of a result set of rows is not a condition
see Getting the Right Data with SQL Joins
|
|

10-08-03, 07:51
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
AHA
SELECT DISTINCT s.name
From Student S, Teaching T, professor p
Where T.profid = P.Id AND
( Select T.Crscode, Trans.stdid, P.Id
From professor p , Teaching T, Transcript Trans
Where p.Iddept <> 'CS'
)
|
|

10-08-03, 07:54
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
you have a cross-join there -- in order to make it an inner join, you will have to add join conditions, e.g. S.teachid=T.id
and you still have an invalid WHERE condition
i'm through for this morning, i have to go to work now
|
|

10-08-03, 07:57
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
Thanx for the link Rudy , This is my last try and I think it will be more accurate:
SELECT DISTINCT s.name
From Student S, Teaching T, professor p
Where (T.profid = P.Id) AND (T.studid = S.id) And
( Select T.Crscode, Trans.stdid, P.Id
From professor p , Teaching T, Transcript Trans
Where p.Iddept <> 'CS'
)
|
|

10-08-03, 07:59
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 15
|
|
Thanx alot Rudy And have a nice time 
|
|
| Thread Tools |
Search this Thread |
|
|
|
| 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
|
|
|
|
|