My question is how can I get data of column1 depending on the column2.
This is a small example of data that I have stored.
create table Student_subject
(
Student varchar(20),
Subject varchar(20)
)
insert into Student_subject
values ('Rohan', 'Maths'),
('Rohan', 'Science'),
('Rohan', 'Language1'),
('RAJ' , 'Maths'),
('RAJ' , 'Science'),
('RAJ' , 'Language1'),
('SAM' , 'Maths'),
('SAM' , 'Language1')
I want to get the distinct row of Students that are studying all three subjects ('Maths', 'Science', 'Language1'). In this case the result will be Rohan and Raj. Please also advise a query on how to achieve the below.
If subjects are specified:
- List of students that are studying { Maths, Science, Language1 }
- List of students that are studying { Maths, Science }