PDA

Click to See Complete Forum and Search --> : Counting records in SQL


Ianpbaker
Apr 11th, 2000, 04:28 PM
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

JHausmann
Apr 11th, 2000, 09:55 PM
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

Ianpbaker
Apr 11th, 2000, 10:20 PM
Thanks Jhausman That was just the ticket.

:D