I am writing a fairly simple web application in PHP which sits on a pre-existing MySQL database which belongs to my client. It is to replace an existing application which will soon shut down.
One of the queries runs very slowly indeed - I haven't benchmarked it, but we're talking seconds, a really noticeable gap. But the existing application, which works in a very similar way, does not have this delay.
I know nothing about optimising SQL queries (in MySQL or anywhere else). Can anyone help me?
The query is:
SELECT `fid`, `enid`, `label`, `activityname`, `date`, `aid_FK`, `extension`
FROM first INNER JOIN second INNER JOIN third
ON first.fid = second.fid_FK AND second.aid_FK = third.aid
WHERE `mem_no_FK` = $var
ORDER BY `date`
Details of the tables are attached as a file.
It may be relevant that table 'first' holds user files - WP documents, spreadsheets, etc. - in its `data` field.