How to show all other records in a Mysql GROUP BY

Discussion in 'MySQL' started by ridesign, Mar 28, 2009.

  1. #1
    I have my query, but I want to show all of name's that are by each of the grouped ip's, currently is just shows 1.

    $query  = "SELECT name, ip1, COUNT(ip1) FROM data GROUP BY ip1 ASC";
    $result = mysql_query($query);
    
    while($row = mysql_fetch_assoc($result))
    {
        echo "<td>{$row['ip1']} </td>" .
             "<td>{$row['COUNT(ip1)']}</td>";
    		 echo "<td>{$row['name']}</td>";
     
    }
    Code (markup):
     
    ridesign, Mar 28, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Your would need to remove group by as it will limit your results to a unique ip1 . Try order by instead of group by.


    $query = "SELECT name, ip1, COUNT(ip1) FROM data ORDER BY ip1 ASC";
     
    jestep, Mar 28, 2009 IP