Ok, as easiest as i can explain.
- There are many child.sid to parent.id
- There are many child.nid to child.sid
- There are many child.id to child.nid
child.id is just the id of a child row. And each row has rating column.
In the query i'm grouping by child.nid. But the results that are being returned are the first entry(lowest child.id) for each nid. What i want is the highest rated child.id for that nid.
$construct = "SELECT child.* FROM outcomes child
JOIN outcomes parent on parent.id=child.sid JOIN
WHERE (parent.name LIKE '%$search%') GROUP BY child.nid,child.sid
ORDER BY child.rating DESC";
I've tried ORDER BY child.rating DESC but this needs to happen before the GROUP BY child.nid.
Any idea how to solve this problem?