I have the following query:
SELECT src_big, created, modified, owner, aid, caption
FROM photo
WHERE aid IN (SELECT aid, modified FROM album WHERE owner IN (SELECT uid2 FROM friend WHERE uid1=me() or uid2 = me())order by modified desc)
ORDER BY created DESC
LIMIT 30
This runs pretty slow, and I’m sure because of the nested SELECT’s etc. How can I make this perform quicker? How should it be rewritten to be better optimized?
try to use joins instead of SubQuery it is faster:
Note: you need to put the table names at the end