Question related to Sql query [message #207457] |
Tue, 05 December 2006 11:34 |
g_p_
Messages: 6 Registered: December 2006
|
Junior Member |
|
|
Good evening,
I have created 4 tables
Student(iid , lname, address)
Teacher(tid, lname, salary, d_number)
Lesson_teach(tid,les_name)
Lesson_attend(iid,les_name)
I'm trying to find the second biggest salary of the teachers
I do:
select distinct T.lname
from teacher T,teacher S
where T.salary > S.salary
Well,in the output i get all the teachers,but i want to take only one who has the second biggest salary.
What else shall i add in order to take the desirable output?
|
|
|
|
|
Re: Question related to Sql query [message #207489 is a reply to message #207485] |
Tue, 05 December 2006 14:47 |
g_p_
Messages: 6 Registered: December 2006
|
Junior Member |
|
|
Thank you very much!
It worked,although the syntax of this sql is a bit difficult for me cause I'm new at sql
Now,i'm trying to find the sudents who attend all the lessons of the processor whose tid = 12 (in relational algebra we use division for this query cause we have "all")
I do :
select Student.lname
from Student,Lesson_attend
where Student.iid = Lesson_attend.iid and Lesson_attend.lno = all(select Lesson_teach.lno
from Lesson_teach,Teacher
where Teacher.tid = Lesson_teach.iid and Teacher.tid= 2)
My tables are :
Student(iid , lname, address)
Teacher(tid, lname, salary, d_number)
Lesson_teach(tid,les_name,lno)
Lesson_attend(iid,les_name,lno) lno is lesson number
The program has to output one Student,cause in my insert.sql file there is only one Student who attends all of his lessons.
I get :no rows selected
Have i done sthg wrong and i don't get the desirable output?
|
|
|
|
|
|
|
|