Comparing two datasets

I'm looking for what SQL would give me the following:


I want to know if a student was enrolled in a college in 2016 and a different college in 2017.

I've tried:

select studentID from college where year = 2017
MINUS
select studentID from college where year = 2016


But it's not working as the student might be in 2017 but not 2016.  Any ideas? Thanks.
Coco BeansDesignerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
select studentID from college where year = 2017 and studentID in (select studentID from college where year = 2016)

Open in new window

0
Coco BeansDesignerAuthor Commented:
That doesn't give you a list of those that are in different colleges?
0
Éric MoreauSenior .Net ConsultantCommented:
Since you want to remove 2016 students, a NOT is missing from Qlemo's query:
select studentID from college where year = 2017 and studentID NOT in (select studentID from college where year = 2016)

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Coco BeansDesignerAuthor Commented:
Sorry if I wasn't clear.  I want to see students that were in enrolled in both 2016, 2017 but that now attend different colleges
0
HuaMin ChenProblem resolverCommented:
Hi,

Do you have any column for college in your table?
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Either that, or you have different tables for different colleges (which would be a bad way to handle). So probably it is something along
select StudentID
from college c1
join college c2 on c1.StudentID = c2.StudentID and c1.year = 2017 and c2.year = 2016
where c1.College != c2.College

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Coco BeansDesignerAuthor Commented:
thank you
0
Éric MoreauSenior .Net ConsultantCommented:
how do you know they went to a different college?

select *
from college 
where year in (2016,2017) 
and studentID NOT in (select studentID from college where DIFFERENT COLLEGE CONDITION)

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.