1

I have a mysql table named X and I wanna count number of occurrences of a tuple. For example we have table X as:

A B
1 2
1 3 
1 2

And I wanna run a query and get results like this:

A B Count
1 2 2
1 3 1

Is there anyway to do so in mysql?!

ahajib
  • 11,406
  • 26
  • 72
  • 114

1 Answers1

2

You need to use Aggregate Function - COUNT in your query.

Use this (assuming your table's name is table1) :

select a, b, COUNT(*) as [Count] FROM table1 group by a, b
Iswanto San
  • 17,718
  • 12
  • 57
  • 79