-- SQL to update the tool_count field in the categories table -- Based on the exact column names confirmed in logs and error message -- CORRECTED VERSION that only uses category_id in news table, not category -- From logs and error message, we know the tables have these columns: -- tools: id, name, slug, description, long_description, category_id, pricing, url, key_features, pros, cons, review, deployment, featured, created_at, updated_at -- news: id, title, content, url, image_url, source, article_date, created_at, updated_at, category_id (NOT category) -- blog_posts: has primary_category_id (based on previous logs) -- categories: id, name, icon, tool_count, created_at, updated_at, slug, description -- 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 - using category_id only, not a category text column 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;