Jump to content

Is a better query possible instead of multiple queries with a for statement?


Recommended Posts

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?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.