-- MINIMAL SQL to update the tool_count field in the categories table -- Using only confirmed columns to avoid any errors -- Update the tool_count in the categories table UPDATE categories c SET tool_count = ( -- Count tools with this category SELECT COUNT(*) FROM tools WHERE category_id = c.id ) + ( -- Count news with this category SELECT COUNT(*) FROM news WHERE category_id = c.id ); -- Output the results for verification SELECT c.id, c.name, c.tool_count, (SELECT COUNT(*) FROM tools WHERE category_id = c.id) AS tools_count, (SELECT COUNT(*) FROM news WHERE category_id = c.id) AS news_count FROM categories c ORDER BY c.tool_count DESC;