sql, subqueries, aggregete queries

I need to write a query that finds all of the members who signed up for the fall conference, but did not sign up for the spring conference.  Does this need a subquery?  What is the best way to write this?
LambelAsked:
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.

Terry WoodsIT GuruCommented:
It can be done without a subquery using an outer join, but the subquery method always is more understandable

The subquery way:

select * from members m
join conference_members cm on cm.member_id =m.id
join conference c on c.id = cm.conference_id
where c.type = 'fall'
and not exists 
(select * from conference_members icm
   join conference ic on ic.id = icm.conference_id
   where ic.type = 'spring'
     and icm.member_id = m.id)

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
Terry WoodsIT GuruCommented:
The outer join way goes something like this. It requires the join to cm2 to fail:

select * from members m
join conference_members cm on cm.member_id =m.id
join conference c on c.id = cm.conference_id
left outer join cm2 on cm2.member_id =m.id
left outer join c2 on c2.id = cm2.conference_id and c2.type = 'spring'
where c.type = 'fall'
and cm2.member_id is null

Open in new window

0
LambelAuthor Commented:
That's perfect! How long will it take me to be able to rip off sql like that??
Thanks very much!
lambel
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
MySQL Server

From novice to tech pro — start learning today.