Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Distinct Count using SQL?

Simple SQL for you SQL experts.

I have two fields (AccountNo, CheckNo). There can be more than 1 checkno that has the same value. It will have the same AccountNo. I would like a listing from mytable displaying AccountNo and CheckNo, as was as the count of how many times it exists.

Select Distinct AccountNo, CheckNo, Count(Distinct AccountNo, CheckNo) as Total
from MyTable
like image 891
IElite Avatar asked Jun 14 '26 18:06

IElite


1 Answers

What you are after is GROUP BY

Select AccountNo, CheckNo, Count(*) as Total
from MyTable
group by AccountNo, CheckNo
like image 113
RichardTheKiwi Avatar answered Jun 16 '26 07:06

RichardTheKiwi