grahamgr3 Posted December 18, 2014 Share Posted December 18, 2014 The select query below returns 1 row when it should be 3. I am pretty sure it is because of the AVG(k.sumtotal) field. If I rewrite the query and take out that AVG(k.sumtotal) column and take out the FROM inv_ratings AS k, I get my 3 rows. I looked online for hours trying to find information about returning results using the AVG clause and didn't find much. Do I have to use a group by clause, I tried that and only get errors. If it is a group by clause please type the exact group by clause to use if you could. thank you. $p = "SELECT i.invention_id, i.inv_title, i.date_submitted, i.category_id, i.approved, c.category_id, c.category, u.image_name, AVG(k.sumtotal) FROM inv_ratings AS k INNER JOIN inventions AS i USING (invention_id) INNER JOIN categories AS c USING (category_id) INNER JOIN images AS u USING (invention_id) WHERE c.category_id = $cat AND i.approved = 'approved' HAVING u.image_name < 2 ORDER BY date_submitted DESC LIMIT $start, $display"; $q = mysqli_query($dbc, $p) or trigger_error("Query: $p\n<br />mysqli Error: " . mysqli_error($dbc)); Link to comment Share on other sites More sharing options...
grahamgr3 Posted December 18, 2014 Author Share Posted December 18, 2014 I found the answer to my own question, I would have deleted the post but I couldn't find the delete option on the site. Link to comment Share on other sites More sharing options...
Larry Posted December 18, 2014 Share Posted December 18, 2014 There is no delete option (for non-admins). Instead, could you share your answer so that others might benefit from your experience? Link to comment Share on other sites More sharing options...
Recommended Posts