Question

I'm working on a social project and there are some tables which will have similar records which i'd like to group them into one. but with my query in brings all the records instead of grouping them into one.

SELECT 
    users_pics.email
    , pic = MIN(pic)
    , count(pic) AS total
    ,fname
    ,lname
    ,profile_pix
    ,RTRIM(wardrobe) as wardrobe
    ,gender
    , resp_email

FROM 
    users_pics  
INNER JOIN 
    profile 
ON 
    users_pics.email = profile.email, dbo.viva_friends

WHERE 
    users_pics.stat = 'new'  
AND  
    resp_email = MMColParam2  
OR   
    req_email= MMColParam 
AND 
    Status = 'Yes '
GROUP BY 
    users_pics.email
    ,fname,lname
    ,profile_pix
    ,wardrobe
    ,gender
    ,req_email
    ,resp_email

ORDER BY 
    MAX(users_pics.u_pic_id) DESC

please is there a way out. when i hit on the run button i get this.

enter image description here

Was it helpful?

Solution

Looks like you just want a simple GROUP BY;

SELECT users_pics.email, MIN(pic) AS pic, COUNT(pic) AS total, MAX(fname) AS fname,
       MAX(lname) AS lname, MAX(profile_pix) AS profile_pic, 
       RTRIM(MAX(wardrobe)) AS wardrobe, MAX(gender) AS gender, MAX(resp_email) resp_email
FROM users_pics  
INNER JOIN profile 
ON users_pics.email = profile.email, 
     dbo.viva_friends
WHERE (users_pics.stat = 'new' AND resp_email = MMColParam2)
   OR (req_email= MMColParam AND Status = 'Yes ')
GROUP BY 
    users_pics.email

Since I can't see your table structure, I can't tell what dbo.viva_friends is used for. It looks like it may be possible to just remove.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top