Thanks akkerend. You did excellent job.
Slimdave, You missed some thing.
10:39:15 SQL> L
1 select student_id
2 from my_table
3 where course in ('java','c')
4 group by student_id
5* having count(distinct course) = 2
10:39:18 SQL> /
STUDENT_ID
----------
13
15
Once again Big Thanks to akkerend.
TamilPHP Code:Another method:
select student_id
from
(
select student_id ,
sum(case
when course = 'c' then 1
else 0
end) c_count,
sum(case
when course = 'java' then 1
else 0
end) java_count,
sum(case
when course <> 'java' and course <> 'c' then 1
else 0
end) oth_count
from my_table
group by student_id
)
where c_count =1 and java_count=1 and oth_count = 0
/
~




Reply With Quote