The following query takes forever to complete and I'm not exactly an SQL guru so I was hoping some of the experts here could take a quick look at it. Can you see anything seriously wrong with it?
Code:
SELECT ord_workorders.*
FROM (ord_workorders
LEFT JOIN ord_reports r1 ON (ord_workorders.id = r1.workorderid AND r1.invoiced = 1))
LEFT JOIN ord_reports r2 ON (ord_workorders.id = r2.workorderid AND r2.invoiced <> 1)
WHERE ord_workorders.completed = 1
AND (r1.workorderid IS NULL OR r2.workorderid IS NOT NULL)
GROUP BY ord_workorders.id ORDER BY ord_workorders.title DESC
When I run it in phpMyAdmin I get one column full of question marks that says (when I hover over them) "You should define a primary key for this table". I've got primary keys on all tables, so what does this message mean?