Select distinct(u.user_name), photo_id, 6_score(1) +6_score(2) +score(3) as rank from images i, group_lists gl, groups g, users u where (contains(SUBJECT, 'weather', 1) >0 OR contains(PLACE, 'weather', 2) >0 OR contains(DESCRIPTION, 'weather', 3) >0 ) and ((i.permitted = gl.group_id and gl.friend_id = u.user_name) OR (i.permitted = 1)) ORDER BY RANK desc;
Select distinct(u.user_name), photo_id, 6_score(1) +6_score(2) +score(3) as rank from images i, group_lists gl, groups g, users u where (contains(SUBJECT, 'weather', 1) >0 OR contains(PLACE, 'weather', 2) >0 OR contains(DESCRIPTION, 'weather', 3) >0 ) and ((i.permitted = gl.group_id and gl.friend_id = u.user_name) OR (i.permitted = 1)) ORDER BY RANK desc;