I have 3 tables: Student
, Address
and StudentAddress
.
Student
stores all the students, address stores all the address details while StudentAddress
resolves many to many relationship between Student
and Address
. This table stores details of student who have lived in more than one addresses.
I am trying to list the Names and address details of a student who has changed his address more than 5 times.
SELECT a.StudentID, CONCAT(b.FirstName + " " + b.LastName), c.MajorMunicipality,
COUNT(a.AddressID) AS count
FROM StudentAddress a
INNER JOIN Member b
ON a.StudentID = b.StudentID
INNER JOIN Address c
ON a.AddressID = b.AddressID
GROUP BY a.StudentID, a.AddressID
HAVING count > 5;
This query has issues with joining. Please help!!