此查询返回登录用户的所有朋友,该朋友出现在以下查询的“网络”表中。这会从这两个表中映射frd_id
和mem_id
。
我已经优化了这个查询。但仍然需要时间来获得结果。
请建议我优化查询。
SELECT m.mem_id,m.profilenam,m.gender,m.photo_thumb,m.profile_type,n.frd_id as mem_id
FROM `network` n
left join members m on(n.frd_id=m.mem_id)
where ((n.frd_id = m.mem_id and n.mem_id=$uid)
or (n.mem_id = m.mem_id and n.frd_id=$uid))
AND m.ban='n'
AND m.deleted<>'Y'
and profilenam like '%'
答案 0 :(得分:0)
试试这个:
SELECT m.mem_id,m.profilenam,m.gender,m.photo_thumb,m.profile_type,m.mem_id
FROM `network` n
JOIN members m ON n.frd_id = m.mem_id
AND ( n.mem_id = $uid
OR ( n.mem_id = m.mem_id
AND n.frd_id = $uid
)
)
WHERE m.profilenam IS NOT NULL
AND m.ban = 'n'
AND m.deleted <> 'Y';