How I fetch friend list friend list from network table.
Below is the URL contain table schema and sample data.I have created following query which id- http://sqlfiddle.com/#!9/646bf/5
SELECT
DISTINCT m.*
FROM members AS m
LEFT JOIN network n1
ON (n1.mem_id = m.mem_id
AND n1.isfriend = 'Y')
LEFT JOIN network n2
ON (n2.frd_id = m.mem_id
AND n2.isfriend = 'Y')
WHERE n2.mem_id = '2'
AND m.profile_type='BB' ORDER BY m.profilenam ASC
This query is also slow and giving duplicate result.
Please help
Your member table has no key that us useful for that query (and index on profile_type AND profilenam would probably help). Similarly the network table has no indexes, and adding one on mem_id would help.
However can't comment on the issue with duplicate results as I don't know what your query is trying to do!