GROUP BYはここでの友達です: select a,b,count(*) from test group by a,b order by a SQLFiddle: https://sqlfiddle.com/#!9/062b0e/5