sql query help

  • I have a CustMaster table in which I have CustomerId as a primary key column and in another table CustDtl I have the CustomerId as foreign key. and I want to generate a sql query such as where it will display me 2 columns, the first column will be the CustomerId and the second column will contain a count of the number of records for that CustomerId value in the CustDtl table(that is for all the CustomerId values in the CustMaster it should display me the count of the corresponding CustomerId  values in the CustDtl table)

    example

    CustomerId  Count

    123             2

    121             4 

     

    Thanks

  • Select CustomerId, COUNT(*) as Total from dbo.CustDtl GROUP BY CustomerId

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply