Assignment 1 Basic SQL - Solutions
Assignment 1 Basic SQL - Solutions
1. select name
from student
where tot_cred>100;
As in the previous query, the join using clause can be used instead. Beware
of using natural join, since that would force the instructor's department to
match the course's department. Your test data should have included a case
where the instructor is from a different department, but has taught a Comp.
Sci. course.
Beware of using natural join for this query, since instructor and course both
have a common attribute dept_name, and natural join makes these equal; as
a result, courses taught by Srinivasan outside his department are excluded.
You can write the query using the using clause though, as
2. select id
from trainhalts
where timein <> timeout and
Note that instead of in, = can be used above, provided that station names
are guaranteed to be unique. This query can also be written using a join, for
example using
select distinct id
from trainhalts, station
where trainhalts.stcode = station.stcode and station.name = 'THANE'
and timein <> timeout
4. select st.name from trainhalts th, train t,station st where th.id=t.id and
st.stcode=th.stcode and t.name='CST-AMR_LOCAL' order by th.seqno;