Using LEFT JOIN to get a count returns a zero count when no data in main table
This is a query that is ALWAYS going to return a value because count(*) will always return something. If you don't want to see that, add a case statement to trap 0 and return null.
How to Query for COUNT on a join table and return records with BOTH count=0 AND count 0
just remove the where condition
from your 2nd query
SELECT p.prodid, p.prodname, avg(r.stars), count(r.stars)
FROM products p
LEFT OUTER JOIN reviews r
ON p.productid=r.productid
GROUP BY p.productid,p.prodname
Related Topics
How to Pivot in Sqlite or I.E. Select in Wide Format a Table Stored in Long Format
Getting Result of Dynamic SQL into a Variable For Sql-Server
Reset Auto Increment Counter in Postgres
Can a Table Field Contain a Hyphen
How to Find All Connected Subgraphs of an Undirected Graph
How to Concatenate Columns in a Postgres Select
How to Create a Cron Job to Run an Postgres SQL Function
Sqlite Database Default Time Value 'Now'
Performing SQL Queries on an Excel Table Within a Workbook With Vba Macro
Get Record Counts For All Tables in MySQL Database
How to Delete Duplicate Rows Without Unique Identifier
What Is Best Tool to Compare Two SQL Server Databases (Schema and Data)
SQL Query to Pivot a Column Using Case When
SQL Performance on Left Outer Join VS Not Exists