March 13, 2007 at 5:28 am
How to check multiple conditions on a single column with and condition.
Lets say theres a table with columns student No and subject.
Data will be as follow.
Student NoSubject
------------------------
00AMath
00AScience
00BMath
00BArts
00CScience
00DMath
00D Science
00DAtrs
00EScience
I want to get Students who are doing both Maths and Science. The results would be 00A and 00D
Please help me to solve this
March 13, 2007 at 6:02 am
select Math.Student_No
from (select Student_No
from yourtable
where Subject = 'Math' ) Math
inner join (select Student_No
from yourtable
where Subject = 'Science' ) Science
on Math.Student_No = Science.Student_No
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 13, 2007 at 6:11 am
or
select StudentId from @yorTable where StudentId in
(select StudentId from @Yourtable where Subject='Science')
and Subject = 'Math'
also does the trick
s
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply