doczaius Posted March 1, 2008 Share Posted March 1, 2008 I have a query issue that I can't figure out without doing it manually with for statements and multiple queries in PHP. I have a "log" table that includes index (PK), userid (FK), pointValue 1, user1, 10 2, user2, 4 3, user1, 10 I have a "hierarchy" table that includes userid (PK), role, location, first, last user9, leader, home, john, doe user1, follower, home, john, hancock user2, follower, away, steve, balmer user4, leader, away, mark, cuban I need to create a descending list of "leaders" with their first and last name and a sum of pointValues that match their location. With the example above I would hope to end up with something like John Doe 20 Mark Cuban 4 With PHP I could run a query for all of the leaders and their locations, then cycle through the array using the location value to create multiple queries to retrieve the sum of point values. Is there any way to do this with just 1 query? Quote Link to comment https://forums.phpfreaks.com/topic/93824-is-a-better-query-possible-instead-of-multiple-queries-with-a-for-statement/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.