Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trouble getting result from join query
Message
From
08/06/2012 11:22:25
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01545667
Message ID:
01545669
Views:
40
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform