我有一个具有多个兴趣的用户表,因此当我查询userinterest
表时,它返回具有多个记录但兴趣不同的同一用户。我试图弄清楚如何在重复数据上加入这些记录,但保留唯一数据。下面我添加了我尝试过的sql语句。
SELECT user.FirstName, user.LastName, user.Profilepix, userinterest.UserId, userinterest.InterestId, interest.Interests, interest.PixLoc
FROM user
INNER JOIN userinterest
ON user.UserId = userinterest.UserId
INNER JOIN interest
ON userinterest.InterestId = interest.InterestId
WHERE user.UserId = 'test1112'
SELECT user.FirstName, user.LastName, user.Profilepix, userinterest.UserId, GROUP_CONCAT(userinterest.InterestId), interest.Interests, interest.PixLoc
FROM user
INNER JOIN userinterest
ON user.UserId = userinterest.UserId
INNER JOIN interest
ON userinterest.InterestId = interest.InterestId
WHERE user.UserId = 'test1112'
当我GROUP_CONCAT
InterestId
时,Interests
和PixLoc
记录会被截断。我如何将它们合并为InterestId
?