SELECT fulltcpnmapports.ip, COUNT(*) as cnt, GROUP_CONCAT(fullnmaptcpports.portid ORDER BY fullnmaptcpports.portid SEPARATOR ', ') as tcpport_list FROM fullnmaptcpports GROUP BY fulltcpnmap.ip ORDER BY fulltcpnmapports.ip;