Using subqueries

I believe that I need to use a subquery to find a solution to my little problem, but it's been so long since I took my DB class that I don't remember too much.

I have a table to which we can call personprogram. This table contains among other data, status, category, id, etc. What I want to find out, are persons who have more than one program in their record:

PersonID   Category   Status
100             1                 1
100             2                 1
101             2                 1
102             1                 1
102             2                 1

So my query would only return two IDs, 100 and 102.

Not sure if a subquery is needed or a group by or having, Need to take a refresher course obviously. Thanks!
Horalia RodriguezIT DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

John EastonDirectorCommented:
I think you are looking for something like the following:
SELECT PersonID FROM (SELECT PersonID, Count(*) AS Tot FROM personprogram GROUP BY PersonID) WHERE Tot > 1;

Open in new window

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
GauthierCommented:
No subqueries needed in this case:
SELECT PersonID, count(PersonId) AS Tot FROM personprogram GROUP BY PersonID HAVING Tot >1

Open in new window

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
Databases

From novice to tech pro — start learning today.