Link to home
Start Free TrialLog in
Avatar of Lia Nungaray
Lia NungarayFlag for United States of America

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of John Easton
John Easton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gauthier
Gauthier

No subqueries needed in this case:
SELECT PersonID, count(PersonId) AS Tot FROM personprogram GROUP BY PersonID HAVING Tot >1

Open in new window