MySQL COUNT help

Posted by space on Stack Overflow See other posts from Stack Overflow or by space
Published on 2010-05-28T06:40:15Z Indexed on 2010/05/28 7:11 UTC
Read the original article Hit count: 173

Filed under:

I'm trying to count all the ids form table3 that are related to the first two tables but I think my SQL code is wrong can some one help me fix it?

Here is the code:

$dbc = mysqli_query($mysqli,"SELECT table1.*, table2.*, COUNT(id) as num, table3.id
                             FROM table1
                             INNER JOIN table2 ON table1.id = table2.id
                             INNER JOIN table3 ON table2.id = table3.id
                             WHERE table2.id = '$id'");

Here is the error message.

Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

© Stack Overflow or respective owner

Related posts about mysql