djp1988 Posted January 9, 2009 Share Posted January 9, 2009 I have a table like so:ID | Ref | ip1 | 6 | 110.10.2.12 | 7 | 112.132.0.13 | 6 | 110.10.2.14 | 8 | 119.10.2.15 | 5 | 110.0.2.16 | 7 | 105.10.1.17 | 6 | 101.10.2.0I wish to do an SQL to get the following result:Ref | Total6 | 37 | 25 | 18 | 1counting the total of each distinct ref. and ordering the resultsI think i need to do an inner join but I don't know how Link to comment Share on other sites More sharing options...
pulpfiction Posted January 9, 2009 Share Posted January 9, 2009 Try this.. You can ignore the ORDER BY part if you need it sorted.SELECT REF, COUNT(*) AS TOTAL FROM TABLE_NAME GROUP BY REF ORDER BY COUNT(*) DESC Link to comment Share on other sites More sharing options...
inktherapy Posted January 15, 2009 Share Posted January 15, 2009 You should also add DISTINCT. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.