I have a table (participants) which has multiple columns that could all be distinct. Two columns that are of special interest in this query are the userID and the programID I have a two part inquery here.
- I want to be able to acquire the list of all userIDs that appear more than once in this table. How do I go about doing it?
I want to be able to acquire the count of all programID's where the same userID appears in multiple programIDs. (I.E. count of programs where same userID appears in 2 programs, count of programs where same USErID appears in 3 programs, etc...) For Example:
programID: prog1 userID: uid1 userID: uid3 userID: uid12 programID: prog2 userID: uid3 userID: uid5 userID: uid14 userID: uid27 programID: prog3 userID: uid3 userID: uid7 userID: uid14 userID: uid30 programID: prog4 userID: uid1
Expected Results: userID count = 2; programs = 3 userID count = 3; programs = 3
Can anyone please help me with this.
my current code for question 1 is:
SELECT
WPP.USERID,
WPI.EMAIL,
WPI.FIRSTNAME,
WPI.LASTNAME,
WPI.INSTITUTION
FROM WEBPROGRAMPARTICIPANTS WPP
INNER JOIN WEBPERSONALINFO WPI
ON WPP.USERID = WPI.USERID
INNER JOIN WEBPROGRAMS WP
ON WPP.PROGRAMCODE = WP.PROGRAMCODE
WHERE
WP.PROGRAMTYPE IN ('1','2','3','4','5','6', '9', '10')
GROUP BY
WPP.USERID,
WPI.EMAIL,
WPI.FIRSTNAME,
WPI.LASTNAME,
WPI.INSTITUTION
HAVING COUNT(WPP.USERID) > 1
ORDER BY WPI.EMAIL