select max(t1.id), t1.uniqueid, t1.status
from table1 t1
left join table1 t2 on t2.uniqueid = t1.uniqueid
and t2.status <> 'no'
where t2.id is null
group by t1.uniqueid
WITH peoples AS (
SELECT * FROM people
WHERE people.name LIKE $(regex)
LIMIT $(limit)
)
SELECT f.*
FROM user_friends f
JOIN peoples p.id = f.friend_id
WHERE user_friends.user_id = $(user_id)