I’ve a ‘items’ table with the following structure:
id, person_id, active
and ‘people’ table with id and name columns.
I want to order by most active items and join the people.name column to sql.
I tried to do something like that, but it’s not working:
SELECT people.id, COUNT(*) as items_count
FROM items, people
WHERE items.active = true AND people.id = items.person_id
GROUP BY items.person_id
ORDER BY items_count DESC
Use Joins this will match the condition. Order by items_count will give you most active user