I need to join two tables to get all the records from the student_info table and just the records from the student_activities table where the student_id’s are equal.
As there can be multiple records in the student activities table for a single student_id I’m getting duplicates when I print the output using a left join.
SELECT *
FROM student_info
LEFT JOIN student_activities
ON student_info.student_id=student_activities.student _id
It was suggested that I use the following but I get errors saying that specific fields are not part of an aggregate function.
SELECT student_info.student_id, student_info.student_name, student_info.phone, student_info.age, COUNT (student_activities.student_id) AS COA
FROM student_info
LEFT OUTER JOIN student_activities
ON student_info.student_id=student_activities.student_id
GROUP BY student_info.student_id
1 Answer