ahajib
ahajib

Reputation: 13510

count tuples in mysql

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?!

Upvotes: 1

Views: 2539

Answers (1)

Iswanto San
Iswanto San

Reputation: 18569

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

Upvotes: 2

Related Questions