You need a group by:
SELECT count(person.lname), ;
sum(pinfo.workhour),lname ;
FROM Person INNER JOIN Pinfo ON person.personid = pinfo.personid ;
WHERE person.personid = 1 ;
or person.personid = 2 ;
GROUP BY lname
>Hi UT,
>
>I am having trouble getting result from a join query. I have 2 tables that contain following information:
>
>
>Table 1: Person
>
>personid lname
>1 Tom
>2 Stacy
>
>
>Table 2: Pinfo
>
>personid workhour
>1 3
>1 2
>1 3
>2 1
>2 5
>2 4
>
>
>I am writng following query where I need a count from Person table and a sum from Pinfo table. Here is my query:
>
>
>SELECT count(person.lname), sum(pinfo.workhour) FROM Person INNER JOIN ;
>Pinfo ON person.personid = pinfo.personid WHERE person.personid = 1 ;
>or person.personid = 2
>
>
>The result I am getting is 6 for the person.lname count and 18 for the sum of workhour. It seems like my person.lname count is count the number of records in Pinfo table. What I really need is a count of 2 for number of person records found and a sum of 18 for the workhours found. Can someone help me figure out why my count for person.lname is wrong and how I should formulate this query.
>
>thanks
>Nick
Peter Cortiel