Results 1 to 3 of 3

Thread: Counting records in SQL

  1. #1

    Thread Starter
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696

    Talking

    I was wondering If some one can help me out.

    I have two tables that I need to retrive data from both have the same primary key (1 to many). I need to display all the information from the first table and how many fields that match in the second table. I've been playing around with the count Funtion and using an inner query but cannot get it to do what I need. Bellow is roughly the way I need it. Thanks in advance for any help.

    SELECT primarykey,field1,field2, count(all the fields in table2 that has the primarykey of table1) FROM table1

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Lightbulb This should work

    try:

    select a.primarykey, a.field1, a.field2, count(b.primarykey) as "Record counts"
    from table1 a, table2 b
    where a.primarykey=b.primarykey
    group by a.primarykey, a.field1, a.field2

  3. #3

    Thread Starter
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696

    Smile

    Thanks Jhausman That was just the ticket.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width